Improve generics usability for `Array<T>`
@9prady9 y travaille déjà.
Depuis le 28/11/2020.
Évaluation
Cette issue n'a pas encore été évaluée.
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?
- Langage dominant
- Rust
- Étoiles
- 827
- Forks
- 59
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de arrayfire/arrayfire-rust
-
Bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
arrayfire/arrayfire-rust#388 ·
-
Bug
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
arrayfire/arrayfire-rust#387 ·
-
Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
arrayfire/arrayfire-rust#386 ·
-
Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
arrayfire/arrayfire-rust#384 ·
-
Bug
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 35/100
arrayfire/arrayfire-rust#385 · 1 commentaire ·
Toutes les issues de arrayfire/arrayfire-rust
Issues similaires
-
Browser (wasm) relay client cannot connect to relays whose URL has a trailing-dot FQDN hostname Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
n0-computer/iroh#4550 ·
-
impl detach for native Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
paritytech/zombienet-sdk#591 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
farion1231/cc-switch#7638 · 1 commentaire ·
-
onnx-ir re-exports ModelProto and GraphProto but not NodeProto, AttributeProto and AttributeType Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100