Convenience of mixed tensor scalar operations
jackerschott opened this issue · 1 comments
jackerschott commented
Suppose I would want to write something like
fn mul_by_two<S : Shape, E : Dtype, D: Device<E>, T : Tape<E, D>>(x : Tensor<S, E, D, T>)
-> Tensor<S, E, D, T>
{
return x * E::from_f32(2.0).unwrap();
}
If I see this correctly I always have to use from_f32
and unwrap
for converting floats to construct a specific generic scalar, which makes larger mathematical functions like this hard to read. It might be an idea to implement a from
method (with associated try_from
) that can be called as just E::from(2.0)
? This would break with the rust conventions though, since from
usually cannot panic, if I see this correctly.
coreylowman commented
Oooh we could change all the scalar impls to accept Rhs: Into<f64>
instead of E
. That should address this? Should clean up the f16 impls as well