Improve generics usability for `Array<T>`
@9prady9 已經在處理了。
開始於 2020年11月28日。
評估
這個 Issue 還沒有評估資料。
描述
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?
- 主要語言
- Rust
- 星號
- 827
- 分支
- 59
- PR 合併指標
- 30 天內沒有已合併 PR
貢獻指南
這個儲存庫沒有索引到貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
arrayfire/arrayfire-rust 的其他 Issue
-
Bug
難度 1/5 1 小時以內 新手友好度 88/100
arrayfire/arrayfire-rust#388 ·
-
Bug
難度 1/5 1 小時以內 新手友好度 88/100
arrayfire/arrayfire-rust#387 ·
-
Bug
難度 2/5 1-3 小時 新手友好度 78/100
arrayfire/arrayfire-rust#386 ·
-
Bug
難度 2/5 1-3 小時 新手友好度 76/100
arrayfire/arrayfire-rust#384 ·
-
Bug
難度 5/5 一週以上 新手友好度 35/100
arrayfire/arrayfire-rust#385 · 1 則留言 ·
查看 arrayfire/arrayfire-rust 的全部 Issue
相似的 Issue
-
bug CLI custom-model
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 75/100
rust-bitcoin/rust-bitcoin#6930 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 75/100
-
難度 2/5 1-3 小時 新手友好度 75/100
fulcrumgenomics/ferro-hgvs#2251 ·
-
A-allocators A-docs C-enhancement T-libs
難度 2/5 1-3 小時 新手友好度 75/100