I have the following Trait implementation and would like to make unit generic over Array1<T>, but fail to find the right Trait bounds (especially that this somehow seems trivial to me, all T needs to support is basically basic arithmetic that output T for the function to work).
trait Unit {
fn unit(&self) -> Array1<f32>;
}
impl Unit for Array1<f32>
{
fn unit(&self) -> Array1<f32> {
self / (self * self).sum().sqrt()
}
}
The compiler suggests adding std::ops::Mul<Output = &ArrayBase<OwnedRepr<T>, Dim<[usize; 1]>>>, but doing so keeps giving the same error over and over.
I followed the compiler error messages and produced this generic code that compiles. I'm not familiar with
ndarrayso I don't know if this is actually correct.Note that
Unitnow returns an associated type. If you want it to always returnf32then you'll need to require thatTcan be converted tof32too.