pub struct Matrix<T> { /* private fields */ }Expand description
A Matrix with generic type items.
Can be indexed by mat[(row, col)]
Implementations§
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn fill(rows: usize, cols: usize, e: T) -> Selfwhere
T: Clone,
pub fn fill(rows: usize, cols: usize, e: T) -> Selfwhere
T: Clone,
Generates a rowsxcols matrix where every element is e
Sourcepub fn build<F: FnMut(usize, usize) -> T>(
rows: usize,
cols: usize,
builder_fn: F,
) -> Self
pub fn build<F: FnMut(usize, usize) -> T>( rows: usize, cols: usize, builder_fn: F, ) -> Self
Generates a rowsxcols matrix where every element is obtained by evaluating builder_fn(row, col)
Sourcepub fn identity(rows: usize) -> Selfwhere
T: MatrixElement,
pub fn identity(rows: usize) -> Selfwhere
T: MatrixElement,
Generates a rowsxrows identity matrix (using MatrixElement::zero() and MatrixElement::one())
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn dim(&self) -> (usize, usize)
pub fn dim(&self) -> (usize, usize)
returns the number of rows and the number of columns of the matrix (in that order)
Sourcepub fn split(self) -> (usize, usize, Vec<T>)
pub fn split(self) -> (usize, usize, Vec<T>)
splits the struct up into its parts, that is into (rows, columns, data)
Sourcepub fn into_some(self) -> Matrix<Option<T>>
pub fn into_some(self) -> Matrix<Option<T>>
Converts a Matrix<T> to a Matrix<Option<T>> by mapping every element e to Some(e)
Sourcepub fn get_mut(&mut self, row: usize, col: usize) -> IndexResult<&mut T>
pub fn get_mut(&mut self, row: usize, col: usize) -> IndexResult<&mut T>
get a mutable reference to the item at (row, col)
§Errors
Returns an error if the index is out of bounds
Sourcepub fn replace(&mut self, row: usize, col: usize, val: T) -> IndexResult<T>
pub fn replace(&mut self, row: usize, col: usize, val: T) -> IndexResult<T>
get a the item at (row, col) and replace it with val
This works like {let res = self.get(row, col); self.set(row, col, val); res} but you get ownership of the returned value
§Errors
Returns an error if the index is out of bounds
Sourcepub fn get_row_mut(
&mut self,
row: usize,
) -> Result<Vec<&mut T>, IndexOutOfBounds<usize>>
pub fn get_row_mut( &mut self, row: usize, ) -> Result<Vec<&mut T>, IndexOutOfBounds<usize>>
get an entire row of (mutable references of) items
§Errors
Returns an error if the row is out of bounds
Sourcepub fn get_col(&self, col: usize) -> Result<Vec<&T>, IndexOutOfBounds<usize>>
pub fn get_col(&self, col: usize) -> Result<Vec<&T>, IndexOutOfBounds<usize>>
get an entire column of (references of) items
§Errors
Returns an error if the column is out of bounds
Sourcepub fn get_col_mut(
&mut self,
col: usize,
) -> Result<Vec<&mut T>, IndexOutOfBounds<usize>>
pub fn get_col_mut( &mut self, col: usize, ) -> Result<Vec<&mut T>, IndexOutOfBounds<usize>>
get an entire column of (mutable references of) items
§Errors
Returns an error if the column is out of bounds
Sourcepub fn map<F: Fn(T) -> U, U>(self, f: F) -> Matrix<U>
pub fn map<F: Fn(T) -> U, U>(self, f: F) -> Matrix<U>
Returns a new Matrix that is obtained by applying the given function to each element
Sourcepub fn transposed(self) -> Self
pub fn transposed(self) -> Self
Returns the Transpose of this Matrix
Sourcepub fn det(self) -> Option<T>
pub fn det(self) -> Option<T>
Returns the Determinant of this Matrix
Source§impl Matrix<RotmatElement>
impl Matrix<RotmatElement>
Sourcepub fn insert_rotation_value<T, O>(self, value: T) -> Matrix<O>
pub fn insert_rotation_value<T, O>(self, value: T) -> Matrix<O>
Takes a previously generated Rotation Matrix and inserts a specific value into it
For f32 and f64, this would be the angle in radians, but for your own type it could be whatever…
(it uses the Trig and the MatrixElement traits to get values for sin, -sin, cos, 0 and 1)
Trait Implementations§
Source§impl<T: Add<U, Output = O>, U, O> Add<Matrix<U>> for Matrix<T>
Adds two matrices element by element
impl<T: Add<U, Output = O>, U, O> Add<Matrix<U>> for Matrix<T>
Adds two matrices element by element
Source§impl<T: Clone + Sub<U, Output = O>, U, O> Sub<Matrix<U>> for Matrix<T>
Subtracts two matrices element by element
impl<T: Clone + Sub<U, Output = O>, U, O> Sub<Matrix<U>> for Matrix<T>
Subtracts two matrices element by element