I'm trying to convert a static matrix into a dynamic matrix using a function. Reason being is that I'm comparing two matrices for unit-testing. Thus the test_value
from the test, and the benchmark
matrices have to be the same element wise. They will only compare though if they're the same type and sometimes the test_value
is a static matrix. I'd like a function that takes in a static matrix type and converts it into a dynamic matrix. So far using the vscode refactor tool I've managed this:
fn matrix_to_dynamic_matrix(matrix: Matrix<f64, Const, Const, ArrayStorage<f64>>) -> Matrix<f64, Dynamic, Dynamic, VecStorage<f64, Dynamic, Dynamic>> {
let matrix_vector:Vec<f64> = matrix.iter().map(|x| x.to_owned()).collect();
let (rows, columns) = matrix.shape();
let matrix_dynamic:DMatrix<f64> = DMatrix::from_vec(rows, columns, matrix_vector);
matrix_dynamic
}
The compiler won't get past the Matrix<f64, Const, Const, ArrayStorage<f64>>
. What the right way to take in the statically sized matrix into the function?
Since you don't know size of static matrix use generic size type for your function: