orx_v::matrices

Trait Matrix

Source
pub trait Matrix<T> {
    // Required methods
    fn num_rows(&self) -> usize;
    fn num_cols(&self) -> usize;
    fn at(&self, idx: impl IntoIdx<D2>) -> T;
    fn all(&self) -> impl Iterator<Item = T>;

    // Provided methods
    fn in_bounds(&self, idx: impl Into<<D2 as Dim>::LeqIdx>) -> bool { ... }
    fn try_at(&self, idx: impl IntoIdx<D2>) -> Option<T> { ... }
    fn equality(&self, other: &impl Matrix<T>) -> Equality<D2>
       where T: PartialEq { ... }
}
Expand description

A matrix or a matrix view over a D2 vector with rectangular cardinality, or over a flattened representation by a D1 vector.

An owned matrix can be created by:

  • calling into_matrix method on a D2 vector implementing NVec<D2, _>, or equivalently, V2<_>; or by:
  • calling v1_into_matrix method on a D1 vector implementing NVec<D1, _>, or equivalently, V1<_>.

Alternatively, matrix views can be created by:

All above mentioned methods have their _mut versions to create a mutable matrix view.

Required Methods§

Source

fn num_rows(&self) -> usize

Number of rows.

Source

fn num_cols(&self) -> usize

Number of columns.

Source

fn at(&self, idx: impl IntoIdx<D2>) -> T

Returns the element at the given idx of the matrix.

§Panics

Panics if the idx is not in_bounds.

Source

fn all(&self) -> impl Iterator<Item = T>

Returns an iterator of all elements of the matrix. The direction of iteration depends on whether the matrix is row-major or column-major.

Row-major matrices are created by:

Column-major matrices are created by:

All above mentioned methods have their _mut versions to create a mutable matrix view.

Provided Methods§

Source

fn in_bounds(&self, idx: impl Into<<D2 as Dim>::LeqIdx>) -> bool

Returns true if the given idx is in bounds of the matrix.

Source

fn try_at(&self, idx: impl IntoIdx<D2>) -> Option<T>

Returns the element at the given idx if it is in_bounds; returns None otherwise.

Source

fn equality(&self, other: &impl Matrix<T>) -> Equality<D2>
where T: PartialEq,

Returns the equality result of comparing this matrix to the other.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, M: Matrix<T>> Matrix<T> for &M

Source§

fn num_rows(&self) -> usize

Source§

fn num_cols(&self) -> usize

Source§

fn at(&self, idx: impl IntoIdx<D2>) -> T

Source§

fn all(&self) -> impl Iterator<Item = T>

Source§

impl<T, M: Matrix<T>> Matrix<T> for &mut M

Source§

fn num_rows(&self) -> usize

Source§

fn num_cols(&self) -> usize

Source§

fn at(&self, idx: impl IntoIdx<D2>) -> T

Source§

fn all(&self) -> impl Iterator<Item = T>

Implementors§

Source§

impl<T, V> Matrix<T> for V2MatrixColMajor<T, V>
where V: NVec<D2, T>,

Source§

impl<T, V> Matrix<T> for V2MatrixRowMajor<T, V>
where V: NVec<D2, T>,

Source§

impl<T, V, L> Matrix<T> for V1Matrix<T, V, L>
where V: NVec<D1, T>, L: V1MatrixLayout,