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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T: Scalar + Scalar, const M: usize, const N: usize> MatrixRef<T> for SMatrix<T, M, N>
where Const<M>: DimName, Const<N>: DimName,

Source§

fn nrows(&self) -> usize

Source§

fn ncols(&self) -> usize

Source§

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

Source§

fn col_as_slice(&self, col: usize, row_start: usize) -> &[T]

Source§

impl<T: Scalar + Scalar> MatrixRef<T> for DMatrix<T>

Source§

fn nrows(&self) -> usize

Source§

fn ncols(&self) -> usize

Source§

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

Source§

fn col_as_slice(&self, col: usize, row_start: usize) -> &[T]

Implementors§

Source§

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

Source§

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

Source§

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