Improve generics usability for `Array<T>`
@9prady9 đang làm issue này rồi.
Từ ngày 28/11/2020.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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?
- Ngôn ngữ chính
- Rust
- Star
- 827
- Fork
- 59
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của arrayfire/arrayfire-rust
-
Bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
arrayfire/arrayfire-rust#388 ·
-
Bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
arrayfire/arrayfire-rust#387 ·
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
arrayfire/arrayfire-rust#386 ·
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
arrayfire/arrayfire-rust#384 ·
-
Bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
arrayfire/arrayfire-rust#385 · 1 bình luận ·
Tất cả issue của arrayfire/arrayfire-rust
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
agentic-workflows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
web-infra-dev/rspack#15847 ·