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
-
todo:perf
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 88/100
-
ACP agents get no MCP servers when the thread is created before the project's first worktree loads 未关闭state:needs triage
难度 2/5 1-3 小时 新手友好度 88/100
zed-industries/zed#64611 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
ontola/atomic-server#1625 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
objectionary/phie#154 ·