Compiling playground v0.0.1 (/playground)
error[E0369]: cannot multiply `ArrayBase<ViewRepr<&{float}>, Dim<[usize; 1]>>` by `ArrayBase<OwnedRepr<{float}>, Dim<[usize; 1]>>`
--> src/main.rs:8:51
|
8 | println!("{:?}", ralph.index_axis(Axis(1), 0) * bob);
| ---------------------------- ^ --- ArrayBase<OwnedRepr<{float}>, Dim<[usize; 1]>>
| |
| ArrayBase<ViewRepr<&{float}>, Dim<[usize; 1]>>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0369`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
It’s less Rust’s fault and more the responsibility of the ndarray crate. I feel like there might be a convention in that crate that the first argument to multiplication has to be owned; but I really don’t know the crate very well. Further test seems to indicate that e.g. both arguments being views or references doesn’t work either and you’d probably have to add something like an into_owned or to_owned call on the first argument if you were to get into such a scenario.
Edit: Currently staring at this implementation I’m doubting if there is such a convention after all...
Edit2: Division doesn’t work either, and that’s not even commutative. Also, if you borrow both arguments it works again, of course this can lead to unnecessary extra allocations. Maybe there’s potential for improvind ndarray here after all. Maybe this kind of improvement is prevented by overlapping implementations though.