hi, do you mean the ndarray crate? The code for its
+= implementation is quite old, so I don’t remember if there is a technical limitation there.
In parts, the ndarray crate errs on the too strict side when it comes to being explicit. The example here would be since that the
+= operator only needs to read from the right hand side operand, it should refuse to consume that operand. The theory is that this helps to avoid unnecessary expensive operations!
As it is now, ndarray has the tools that let you express this without intermediate arrays, but around that, there’s an even more tricky question of making a nice interface for it.
Can you look into using
general_mat_vec_mul to compute the matrix multiplication, scaling, and addition in one go? It’s not exactly easy to use either, but in theory it does this efficiently.
There are a few more general and specific methods like
.zip_mut_with or using
Zip for custom array traversals that perform elementwise operations,
There are other Rust crates that experiment with more convenient ways to express this, but I don’t really know what they have achieved in comparison.