Trait Matrix

Source
pub trait Matrix: VectorSpace
where Self::Scalar: Float, Self: Index<usize, Output = Self::Column> + IndexMut<usize, Output = Self::Column>,
{ type Row: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>; type Column: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>; type Transpose: Matrix<Scalar = Self::Scalar, Row = Self::Column, Column = Self::Row>; // Required methods fn row(&self, r: usize) -> Self::Row; fn swap_rows(&mut self, a: usize, b: usize); fn swap_columns(&mut self, a: usize, b: usize); fn swap_elements(&mut self, a: (usize, usize), b: (usize, usize)); fn transpose(&self) -> Self::Transpose; // Provided methods fn as_ptr(&self) -> *const Self::Scalar { ... } fn as_mut_ptr(&mut self) -> *mut Self::Scalar { ... } fn replace_col(&mut self, c: usize, src: Self::Column) -> Self::Column { ... } }
Expand description

A column-major matrix of arbitrary dimensions.

Because this is constrained to the VectorSpace trait, this means that following operators are required to be implemented:

Matrix addition:

  • Add<Output = Self>
  • Sub<Output = Self>
  • Neg<Output = Self>

Scalar multiplication:

  • Mul<Self::Scalar, Output = Self>
  • Div<Self::Scalar, Output = Self>
  • Rem<Self::Scalar, Output = Self>

Note that matrix multiplication is not required for implementors of this trait. This is due to the complexities of implementing these operators with Rust’s current type system. For the multiplication of square matrices, see SquareMatrix.

Required Associated Types§

Source

type Row: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>

The row vector of the matrix.

Source

type Column: VectorSpace<Scalar = Self::Scalar> + Array<Element = Self::Scalar>

The column vector of the matrix.

Source

type Transpose: Matrix<Scalar = Self::Scalar, Row = Self::Column, Column = Self::Row>

The result of transposing the matrix

Required Methods§

Source

fn row(&self, r: usize) -> Self::Row

Get a row from this matrix by-value.

Source

fn swap_rows(&mut self, a: usize, b: usize)

Swap two rows of this array.

Source

fn swap_columns(&mut self, a: usize, b: usize)

Swap two columns of this array.

Source

fn swap_elements(&mut self, a: (usize, usize), b: (usize, usize))

Swap the values at index a and b

Source

fn transpose(&self) -> Self::Transpose

Transpose this matrix, returning a new matrix.

Provided Methods§

Source

fn as_ptr(&self) -> *const Self::Scalar

Get the pointer to the first element of the array.

Source

fn as_mut_ptr(&mut self) -> *mut Self::Scalar

Get a mutable pointer to the first element of the array.

Source

fn replace_col(&mut self, c: usize, src: Self::Column) -> Self::Column

Replace a column in the array.

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.

Implementors§