pub struct Matrix<T, const M: usize, const N: usize> { /* private fields */ }
Expand description
Represents a matrix with constant M
rows and constant N
columns.
The underlying data is represented as an array and is always stored in column-major order.
See the crate root for usage examples.
Implementations§
Source§impl<T, const M: usize, const N: usize> Matrix<T, M, N>
impl<T, const M: usize, const N: usize> Matrix<T, M, N>
Sourcepub fn repeat(element: T) -> Selfwhere
T: Copy,
pub fn repeat(element: T) -> Selfwhere
T: Copy,
Create a new matrix filled with the given element.
Sourcepub fn repeat_with<F>(f: F) -> Selfwhere
F: FnMut() -> T,
pub fn repeat_with<F>(f: F) -> Selfwhere
F: FnMut() -> T,
Create a new matrix filled with computed elements.
Elements will be filled in column-major order.
Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Views the underlying data as a contiguous mutable slice.
Sourcepub fn get<I>(&self, i: I) -> Option<&I::Output>where
I: MatrixIndex<Self>,
pub fn get<I>(&self, i: I) -> Option<&I::Output>where
I: MatrixIndex<Self>,
Returns a reference to an element in the matrix or None
if out of
bounds.
Sourcepub fn get_mut<I>(&mut self, i: I) -> Option<&mut I::Output>where
I: MatrixIndex<Self>,
pub fn get_mut<I>(&mut self, i: I) -> Option<&mut I::Output>where
I: MatrixIndex<Self>,
Returns a mutable reference to an element in the matrix or None
if out
of bounds.
Sourcepub unsafe fn get_unchecked<I>(&self, i: I) -> &I::Outputwhere
I: MatrixIndex<Self>,
pub unsafe fn get_unchecked<I>(&self, i: I) -> &I::Outputwhere
I: MatrixIndex<Self>,
Returns a reference to an element in the matrix without doing any bounds checking.
§Safety
Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used.
Sourcepub unsafe fn get_unchecked_mut<I>(&mut self, i: I) -> &mut I::Outputwhere
I: MatrixIndex<Self>,
pub unsafe fn get_unchecked_mut<I>(&mut self, i: I) -> &mut I::Outputwhere
I: MatrixIndex<Self>,
Returns a mutable reference to an element in the matrix without doing any bounds checking.
§Safety
Calling this method with an out-of-bounds index is undefined behavior even if the resulting reference is not used.
Sourcepub fn row(&self, i: usize) -> &Row<T, M, N>
pub fn row(&self, i: usize) -> &Row<T, M, N>
Returns a reference to the i
-th row of this matrix.
Sourcepub fn row_mut(&mut self, i: usize) -> &mut Row<T, M, N>
pub fn row_mut(&mut self, i: usize) -> &mut Row<T, M, N>
Returns a mutable reference to the i
-th row of this matrix.
Sourcepub fn column(&self, i: usize) -> &Column<T, M, N>
pub fn column(&self, i: usize) -> &Column<T, M, N>
Returns a reference to the i
-th column of this matrix.
Sourcepub fn column_mut(&mut self, i: usize) -> &mut Column<T, M, N>
pub fn column_mut(&mut self, i: usize) -> &mut Column<T, M, N>
Returns a mutable reference to the i
-th column of this matrix.
Sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>
pub fn iter_mut(&mut self) -> IterMut<'_, T>
Returns a mutable iterator over the underlying data.
Sourcepub fn iter_rows(&self) -> IterRows<'_, T, M, N> ⓘ
pub fn iter_rows(&self) -> IterRows<'_, T, M, N> ⓘ
Returns an iterator over the rows in this matrix.
Sourcepub fn iter_rows_mut(&mut self) -> IterRowsMut<'_, T, M, N> ⓘ
pub fn iter_rows_mut(&mut self) -> IterRowsMut<'_, T, M, N> ⓘ
Returns a mutable iterator over the rows in this matrix.
Sourcepub fn iter_columns(&self) -> IterColumns<'_, T, M, N> ⓘ
pub fn iter_columns(&self) -> IterColumns<'_, T, M, N> ⓘ
Returns an iterator over the columns in this matrix.
Sourcepub fn iter_columns_mut(&mut self) -> IterColumnsMut<'_, T, M, N> ⓘ
pub fn iter_columns_mut(&mut self) -> IterColumnsMut<'_, T, M, N> ⓘ
Returns a mutable iterator over the columns in this matrix.
Sourcepub fn map<F, U>(self, f: F) -> Matrix<U, M, N>where
F: FnMut(T) -> U,
pub fn map<F, U>(self, f: F) -> Matrix<U, M, N>where
F: FnMut(T) -> U,
Returns a matrix of the same size as self, with function f
applied to
each element in column-major order.
Sourcepub fn l1_norm(&self) -> T
pub fn l1_norm(&self) -> T
Returns the L1 norm of the matrix.
Also known as Manhattan Distance or Taxicab norm. L1 Norm is the sum of the magnitudes of the vectors in a space.
§Note
If the matrix is a row vector this method might not do what you what you expect. For example:
let row_vector = matrix![1, 2, 3];
assert_eq!(row_vector.l1_norm(), 3);
let column_vector = matrix![1; 2; 3];
assert_eq!(column_vector.l1_norm(), 6);
Trait Implementations§
Source§impl<T, const M: usize, const N: usize> AddAssign<&Matrix<T, M, N>> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> AddAssign<&Matrix<T, M, N>> for Matrix<T, M, N>
Source§fn add_assign(&mut self, other: &Matrix<T, M, N>)
fn add_assign(&mut self, other: &Matrix<T, M, N>)
+=
operation. Read moreSource§impl<T, const M: usize, const N: usize> AddAssign<&T> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> AddAssign<&T> for Matrix<T, M, N>
Source§fn add_assign(&mut self, other: &T)
fn add_assign(&mut self, other: &T)
+=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> AddAssign<T> for Matrix<T, M, N>
impl<'a, T, const M: usize, const N: usize> AddAssign<T> for Matrix<T, M, N>
Source§fn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
+=
operation. Read moreSource§impl<T, const M: usize, const N: usize> AddAssign for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> AddAssign for Matrix<T, M, N>
Source§fn add_assign(&mut self, other: Matrix<T, M, N>)
fn add_assign(&mut self, other: Matrix<T, M, N>)
+=
operation. Read moreSource§impl<T, const M: usize, const N: usize> BitAndAssign<&T> for Matrix<T, M, N>where
T: Copy + BitAndAssign<T>,
impl<T, const M: usize, const N: usize> BitAndAssign<&T> for Matrix<T, M, N>where
T: Copy + BitAndAssign<T>,
Source§fn bitand_assign(&mut self, other: &T)
fn bitand_assign(&mut self, other: &T)
&=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> BitAndAssign<T> for Matrix<T, M, N>where
T: Copy + BitAndAssign<T>,
impl<'a, T, const M: usize, const N: usize> BitAndAssign<T> for Matrix<T, M, N>where
T: Copy + BitAndAssign<T>,
Source§fn bitand_assign(&mut self, other: T)
fn bitand_assign(&mut self, other: T)
&=
operation. Read moreSource§impl<T, const M: usize, const N: usize> BitOrAssign<&T> for Matrix<T, M, N>where
T: Copy + BitOrAssign<T>,
impl<T, const M: usize, const N: usize> BitOrAssign<&T> for Matrix<T, M, N>where
T: Copy + BitOrAssign<T>,
Source§fn bitor_assign(&mut self, other: &T)
fn bitor_assign(&mut self, other: &T)
|=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> BitOrAssign<T> for Matrix<T, M, N>where
T: Copy + BitOrAssign<T>,
impl<'a, T, const M: usize, const N: usize> BitOrAssign<T> for Matrix<T, M, N>where
T: Copy + BitOrAssign<T>,
Source§fn bitor_assign(&mut self, other: T)
fn bitor_assign(&mut self, other: T)
|=
operation. Read moreSource§impl<T, const M: usize, const N: usize> BitXorAssign<&T> for Matrix<T, M, N>where
T: Copy + BitXorAssign<T>,
impl<T, const M: usize, const N: usize> BitXorAssign<&T> for Matrix<T, M, N>where
T: Copy + BitXorAssign<T>,
Source§fn bitxor_assign(&mut self, other: &T)
fn bitxor_assign(&mut self, other: &T)
^=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> BitXorAssign<T> for Matrix<T, M, N>where
T: Copy + BitXorAssign<T>,
impl<'a, T, const M: usize, const N: usize> BitXorAssign<T> for Matrix<T, M, N>where
T: Copy + BitXorAssign<T>,
Source§fn bitxor_assign(&mut self, other: T)
fn bitxor_assign(&mut self, other: T)
^=
operation. Read moreSource§impl<T: Default, const M: usize, const N: usize> Default for Matrix<T, M, N>
impl<T: Default, const M: usize, const N: usize> Default for Matrix<T, M, N>
Source§impl<T, const M: usize, const N: usize> DivAssign<&T> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> DivAssign<&T> for Matrix<T, M, N>
Source§fn div_assign(&mut self, other: &T)
fn div_assign(&mut self, other: &T)
/=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> DivAssign<T> for Matrix<T, M, N>
impl<'a, T, const M: usize, const N: usize> DivAssign<T> for Matrix<T, M, N>
Source§fn div_assign(&mut self, other: T)
fn div_assign(&mut self, other: T)
/=
operation. Read moreSource§impl<T, const M: usize, const N: usize> FromIterator<T> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> FromIterator<T> for Matrix<T, M, N>
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Create a new matrix from an iterator.
Elements will be filled in column-major order.
§Panics
If the iterator doesn’t yield enough elements to fill the matrix.
Source§impl<T, I, const M: usize, const N: usize> Index<I> for Matrix<T, M, N>where
I: MatrixIndex<Self>,
impl<T, I, const M: usize, const N: usize> Index<I> for Matrix<T, M, N>where
I: MatrixIndex<Self>,
Source§impl<T, I, const M: usize, const N: usize> IndexMut<I> for Matrix<T, M, N>where
I: MatrixIndex<Self>,
impl<T, I, const M: usize, const N: usize> IndexMut<I> for Matrix<T, M, N>where
I: MatrixIndex<Self>,
Source§impl<T, const M: usize, const N: usize> MatrixIndex<Matrix<T, M, N>> for (usize, usize)
impl<T, const M: usize, const N: usize> MatrixIndex<Matrix<T, M, N>> for (usize, usize)
Source§fn get(self, matrix: &Matrix<T, M, N>) -> Option<&Self::Output>
fn get(self, matrix: &Matrix<T, M, N>) -> Option<&Self::Output>
Source§fn get_mut(self, matrix: &mut Matrix<T, M, N>) -> Option<&mut Self::Output>
fn get_mut(self, matrix: &mut Matrix<T, M, N>) -> Option<&mut Self::Output>
Source§unsafe fn get_unchecked(
self,
matrix: *const Matrix<T, M, N>,
) -> *const Self::Output
unsafe fn get_unchecked( self, matrix: *const Matrix<T, M, N>, ) -> *const Self::Output
Source§unsafe fn get_unchecked_mut(
self,
matrix: *mut Matrix<T, M, N>,
) -> *mut Self::Output
unsafe fn get_unchecked_mut( self, matrix: *mut Matrix<T, M, N>, ) -> *mut Self::Output
Source§impl<T, const M: usize, const N: usize> MatrixIndex<Matrix<T, M, N>> for usize
impl<T, const M: usize, const N: usize> MatrixIndex<Matrix<T, M, N>> for usize
Source§fn get(self, matrix: &Matrix<T, M, N>) -> Option<&Self::Output>
fn get(self, matrix: &Matrix<T, M, N>) -> Option<&Self::Output>
Source§fn get_mut(self, matrix: &mut Matrix<T, M, N>) -> Option<&mut Self::Output>
fn get_mut(self, matrix: &mut Matrix<T, M, N>) -> Option<&mut Self::Output>
Source§unsafe fn get_unchecked(
self,
matrix: *const Matrix<T, M, N>,
) -> *const Self::Output
unsafe fn get_unchecked( self, matrix: *const Matrix<T, M, N>, ) -> *const Self::Output
Source§unsafe fn get_unchecked_mut(
self,
matrix: *mut Matrix<T, M, N>,
) -> *mut Self::Output
unsafe fn get_unchecked_mut( self, matrix: *mut Matrix<T, M, N>, ) -> *mut Self::Output
Source§impl<T, const N: usize, const M: usize, const P: usize> Mul<&Matrix<T, N, P>> for &Matrix<T, M, N>
impl<T, const N: usize, const M: usize, const P: usize> Mul<&Matrix<T, N, P>> for &Matrix<T, M, N>
Source§impl<T, const N: usize, const M: usize, const P: usize> Mul<&Matrix<T, N, P>> for Matrix<T, M, N>
impl<T, const N: usize, const M: usize, const P: usize> Mul<&Matrix<T, N, P>> for Matrix<T, M, N>
Source§impl<T, const N: usize, const M: usize, const P: usize> Mul<Matrix<T, N, P>> for &Matrix<T, M, N>
impl<T, const N: usize, const M: usize, const P: usize> Mul<Matrix<T, N, P>> for &Matrix<T, M, N>
Source§impl<T, const N: usize, const M: usize, const P: usize> Mul<Matrix<T, N, P>> for Matrix<T, M, N>
impl<T, const N: usize, const M: usize, const P: usize> Mul<Matrix<T, N, P>> for Matrix<T, M, N>
Source§impl<T, const M: usize, const N: usize> MulAssign<&T> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> MulAssign<&T> for Matrix<T, M, N>
Source§fn mul_assign(&mut self, other: &T)
fn mul_assign(&mut self, other: &T)
*=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> MulAssign<T> for Matrix<T, M, N>
impl<'a, T, const M: usize, const N: usize> MulAssign<T> for Matrix<T, M, N>
Source§fn mul_assign(&mut self, other: T)
fn mul_assign(&mut self, other: T)
*=
operation. Read moreSource§impl<T: Ord, const M: usize, const N: usize> Ord for Matrix<T, M, N>
impl<T: Ord, const M: usize, const N: usize> Ord for Matrix<T, M, N>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T: PartialOrd, const M: usize, const N: usize> PartialOrd for Matrix<T, M, N>
impl<T: PartialOrd, const M: usize, const N: usize> PartialOrd for Matrix<T, M, N>
Source§impl<T, const M: usize, const N: usize> RemAssign<&T> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> RemAssign<&T> for Matrix<T, M, N>
Source§fn rem_assign(&mut self, other: &T)
fn rem_assign(&mut self, other: &T)
%=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> RemAssign<T> for Matrix<T, M, N>
impl<'a, T, const M: usize, const N: usize> RemAssign<T> for Matrix<T, M, N>
Source§fn rem_assign(&mut self, other: T)
fn rem_assign(&mut self, other: T)
%=
operation. Read moreSource§impl<T, const M: usize, const N: usize> ShlAssign<&T> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> ShlAssign<&T> for Matrix<T, M, N>
Source§fn shl_assign(&mut self, other: &T)
fn shl_assign(&mut self, other: &T)
<<=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> ShlAssign<T> for Matrix<T, M, N>
impl<'a, T, const M: usize, const N: usize> ShlAssign<T> for Matrix<T, M, N>
Source§fn shl_assign(&mut self, other: T)
fn shl_assign(&mut self, other: T)
<<=
operation. Read moreSource§impl<T, const M: usize, const N: usize> ShrAssign<&T> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> ShrAssign<&T> for Matrix<T, M, N>
Source§fn shr_assign(&mut self, other: &T)
fn shr_assign(&mut self, other: &T)
>>=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> ShrAssign<T> for Matrix<T, M, N>
impl<'a, T, const M: usize, const N: usize> ShrAssign<T> for Matrix<T, M, N>
Source§fn shr_assign(&mut self, other: T)
fn shr_assign(&mut self, other: T)
>>=
operation. Read moreSource§impl<T, const M: usize, const N: usize> SubAssign<&Matrix<T, M, N>> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> SubAssign<&Matrix<T, M, N>> for Matrix<T, M, N>
Source§fn sub_assign(&mut self, other: &Matrix<T, M, N>)
fn sub_assign(&mut self, other: &Matrix<T, M, N>)
-=
operation. Read moreSource§impl<T, const M: usize, const N: usize> SubAssign<&T> for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> SubAssign<&T> for Matrix<T, M, N>
Source§fn sub_assign(&mut self, other: &T)
fn sub_assign(&mut self, other: &T)
-=
operation. Read moreSource§impl<'a, T, const M: usize, const N: usize> SubAssign<T> for Matrix<T, M, N>
impl<'a, T, const M: usize, const N: usize> SubAssign<T> for Matrix<T, M, N>
Source§fn sub_assign(&mut self, other: T)
fn sub_assign(&mut self, other: T)
-=
operation. Read moreSource§impl<T, const M: usize, const N: usize> SubAssign for Matrix<T, M, N>
impl<T, const M: usize, const N: usize> SubAssign for Matrix<T, M, N>
Source§fn sub_assign(&mut self, other: Matrix<T, M, N>)
fn sub_assign(&mut self, other: Matrix<T, M, N>)
-=
operation. Read more