Any way to dot arrays of different type?
As far as I understand it, the current implementation of the Dot Trait does not allow the user to dot Arrays containing different data types. Why is that and is there any way to get around this limitation?
To be clear, what i need is something like this:
impl<A, B, S, S2> Dot<ArrayBase<S2, Dim<[usize; 2]>>> for ArrayBase<S, Ix2> where
S: Data<Elem = A>,
S2: Data<Elem = B>,
A: LinalgScalar,
B: LinalgScalar + Add<Rhs = A> + Mul<Rhs = A>,
As long as the Add and Mul trait bounds are satisfied, it should be possible to use the two data types in a dot operation, right?
Sorry if I am missing something obvious here.
I think this would make for a good PR actually. As you say, the element trait bounds are the only limiting factor here, so there's no reason not to do this (except for monomorphization bloat I guess)
Just to help frame this issue, the main reason for this "dot" is to support matrix-matrix multiplication, where we interface to matrixmultiply or blas for floating point types and don't care so much about other element types (this is the de facto situation).
With that framing, the reason we expose it like this currnently is that blas and matrixmultiply support symmetrical ops and not ops with mixed types. Mixing f32 with f64 would then be orders of magnitude slower than f64-f64 matrix multiply. I usually like exposing mainly what we can do well.
I can see the merit to this. With a heterogeneous dot() implementation it would be difficult for users to see why the same method is sometimes running slower. Can this be solved with better method documentation?
I agree that we shouldn't expose dot for a combination of f32 and f64, but that's not an issue for the proposed type signature, since Add and Mul aren't implemented for a combination of f32 and f64 anyway. This proposal seems good to me.