Improve generics usability for `Array<T>`
@9prady9 is already working on this.
Since Nov 28, 2020.
Assessment
This issue has not been assessed yet.
Description
I encountered difficulty when writing generic functions using Array<T> e.g.
fn test_basic_op<T>(a: &af::Array<T>)
where
// T: af::Fromf64 + af::HasAfEnum + ???
{
println!("Element-wise arithmetic");
let b = af::add(&af::sin(a), &T::fromf64(1.5f64), false);
let b2 = af::add(&af::sin(a), &af::cos(a), false);
let b3 = !a;
af::af_print!("sin(a) + 1.5 => ", b);
af::af_print!("sin(a) + cos(a) => ", b2);
af::af_print!("!a => ", b3);
let a_plus_b = a.clone() + b.clone();
af::af_print!("a + b", a_plus_b);
let minus_a = -(a.clone());
af::af_print!("-a ", minus_a);
}
After long fight with compile error, I found that
fn test_basic_op<T>(a: &af::Array<T>)
where
T: af::HasAfEnum<UnaryOutType = T>
+ af::Fromf64
+ af::Convertable<OutType = T>
+ af::ImplicitPromote<T, Output = T>,
af::Array<T>: std::ops::Neg<Output = af::Array<T>>,
{
...
}
compiles and it's OK.
However, I feel that:
ConvertableandImplicitPromoteseems implementation detail and I don't want to write them every time when usingArray<T>.Tshould beConvertable<OutType=T>automatically whenT: HasAfEnum(i.e.Tis supported inarrayfire).
So I want:
- Alias-like trait (e.g.
AfScalar: HasAfEnum + ...) which enables us ignoring implementation detail when usingArray<T>in generic code - Generic trait implementation (e.g.
Convertable), not implementation forf32,f64and other types individually
What are your thoughts?
- Dominant language
- Rust
- Stars
- 827
- Forks
- 59
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from arrayfire/arrayfire-rust
-
Bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
arrayfire/arrayfire-rust#388 ·
-
Bug
Difficulty 1/5 Under an hour Newbie friendliness 88/100
arrayfire/arrayfire-rust#387 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
arrayfire/arrayfire-rust#386 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
arrayfire/arrayfire-rust#384 ·
-
Bug
Difficulty 5/5 Over a week Newbie friendliness 35/100
arrayfire/arrayfire-rust#385 · 1 comment ·
All issues in arrayfire/arrayfire-rust
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
issue
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
agentic-workflows
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
web-infra-dev/rspack#15847 ·