Skip to main content

MatrixRef

Trait MatrixRef 

Source
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§

Source

fn nrows(&self) -> usize

Number of rows.

Source

fn ncols(&self) -> usize

Number of columns.

Source

fn get(&self, row: usize, col: usize) -> &T

Reference to the element at (row, col).

Source

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.

Implementors§

Source§

impl<T> MatrixRef<T> for DynMatrix<T>

Source§

impl<T> MatrixRef<T> for DynVector<T>

Source§

impl<T, const M: usize, const N: usize> MatrixRef<T> for Matrix<T, M, N>