How to perform repeated multiplications with DMatrix

I have the following code

pub fn lie_jacobian(generator_x: Matrix3x4<MatrixData>,
                generator_y: Matrix3x4<MatrixData>,
                generator_z: Matrix3x4<MatrixData>,
                generator_roll: Matrix3x4<MatrixData>,
                generator_pitch: Matrix3x4<MatrixData>,
                generator_yaw: Matrix3x4<MatrixData>,
                Y_est: DMatrix<MatrixData>) -> () {
let N = Y_est.ncols();

let G_1_y = generator_x*Y_est;
let G_1_y_stacked = stack(G_1_y);

let G_2_y = generator_y*Y_est;
let G_2_y_stacked = stack(G_2_y);

....

Since DMatrix does not implement the copy trait I get the following error

error[E0382]: use of moved value: `Y_est`

|
48 |                     Y_est: DMatrix<MatrixData>) -> () {
|                     ----- move occurs because `Y_est` has type `image::na::Matrix<f64,    image::na::Dynamic, image::na::Dynamic, image::na::VecStorage<f64, image::na::Dynamic, image::na::Dynamic>>`, which does not implement the `Copy` trait
...
51 |     let G_1_y = generator_x*Y_est;
|                             ----- value moved here
...
54 |     let G_2_y = generator_y*Y_est;
|                             ^^^^^ value used here after move

Matrix multiplication is not mutable, so in theory I should be able to reuse Y_est without cloning(?). Or maybe a different way of asking. Does clone() on a DMatrix perform a deep copy?

Hi!

Yes, clone() performs a deep copy (including an allocation).
You can use a reference to Y_est to perform the multiplication without moving it: generator_x * &Y_est and generator_y * &Y_est.

Thank you for your response. This was definitely me not understanding borrowing semantics in Rust.