I am using nalgebra and I want to modify one matrix by setting it as the columns of another with compatible dimensions, like this:
let zero: T = convert(0.0);
let mut basis = DMatrix::from_element(rows, rank, zero);
// matrix is an input with dimensions rows x cols
for i in 0..location.len()
{
basis.column_mut(i) = matrix.column(location[i]);
}
I have also tried dereferencing both sides of the assignment and looked for an "assign" method of some kind, no luck.
set_column
doesn't work because DMatrix
does not implement DimName
My current work around is this, but I don;t like it one bit:
// Construct basis vectors initialized to 0.
let zero: T = convert(0.0);
let mut basis = DMatrix::from_element(rows, rank, zero);
for i in 0..location.len()
{
// Copy the pivot column from the matrix.
let col = location[i];
for r in 0..matrix.nrows()
{
basis[(r, i)] = matrix[(r, col)];
}
}