pub trait MatrixRef<T> {
// Required methods
fn nrows(&self) -> usize;
fn ncols(&self) -> usize;
fn get(&self, row: usize, col: usize) -> &T;
fn col_as_slice(&self, col: usize, row_start: usize) -> &[T];
}Expand description
Read-only access to a matrix-like type.
This trait allows algorithms to operate generically over
both fixed-size Matrix and future DynMatrix types.
§Example
use numeris::{Matrix, MatrixRef};
fn trace<T: numeris::Scalar>(m: &impl MatrixRef<T>) -> T {
let mut sum = T::zero();
let n = m.nrows().min(m.ncols());
for i in 0..n {
sum = sum + *m.get(i, i);
}
sum
}
let m = Matrix::new([[1.0, 2.0], [3.0, 4.0]]);
assert_eq!(trace(&m), 5.0);Required Methods§
Sourcefn col_as_slice(&self, col: usize, row_start: usize) -> &[T]
fn col_as_slice(&self, col: usize, row_start: usize) -> &[T]
Contiguous slice of column col from row row_start to end.
Returns &[T] of length nrows - row_start. Available because
both Matrix and DynMatrix use column-major contiguous storage.