pub struct Matrix<T: Clone> { /* private fields */ }
Expand description
A dynamically sized matrix with entries of a type T
Data is stored column-wise, so adjacent elements of the flatmap vector are in the same column (modulo column breaks)
If T is a Ring, many more useful operations open up. When T is an abstract data type, this is pretty much only useful for storage.
Implementations§
Source§impl<T: Clone> Matrix<T>
impl<T: Clone> Matrix<T>
Sourcepub fn from_flatmap(rows: usize, cols: usize, flatmap: Vec<T>) -> Matrix<T>
pub fn from_flatmap(rows: usize, cols: usize, flatmap: Vec<T>) -> Matrix<T>
Constructs a matrix from a flat vector
Sourcepub fn from_index_def(
rows: usize,
cols: usize,
at_index: &mut dyn FnMut(usize, usize) -> T,
) -> Matrix<T>
pub fn from_index_def( rows: usize, cols: usize, at_index: &mut dyn FnMut(usize, usize) -> T, ) -> Matrix<T>
Constructs a matrix defined index-wise
Sourcepub fn is_row_vector(&self) -> bool
pub fn is_row_vector(&self) -> bool
Returns whether or not this is a row vector
Sourcepub fn append_col_ref(&mut self, col: &mut Vec<T>)
pub fn append_col_ref(&mut self, col: &mut Vec<T>)
Appends a reference to a column to this matrix on the right
Sourcepub fn append_mat_right_ref(&mut self, mat: &mut Matrix<T>)
pub fn append_mat_right_ref(&mut self, mat: &mut Matrix<T>)
Appends a reference to a matrix to this matrix on the right
Sourcepub fn append_col(&mut self, col: Vec<T>)
pub fn append_col(&mut self, col: Vec<T>)
Appends a column to this matrix on the right
Sourcepub fn append_mat_right(&mut self, mat: Matrix<T>)
pub fn append_mat_right(&mut self, mat: Matrix<T>)
Appends a matrix to this matrix, on the right
Sourcepub fn append_row(&mut self, row: Vec<T>)
pub fn append_row(&mut self, row: Vec<T>)
Appends a row to this matrix on the bottom
Sourcepub fn append_mat_bottom(&mut self, mat: Matrix<T>)
pub fn append_mat_bottom(&mut self, mat: Matrix<T>)
Appends a matrix to this matrix, on the bottom
Sourcepub fn applying_to_all<J: Ring>(&self, f: &dyn Fn(T) -> J) -> Matrix<J>
pub fn applying_to_all<J: Ring>(&self, f: &dyn Fn(T) -> J) -> Matrix<J>
Applies a function to all entries in this matrix, returning the result as a separate matrix
Sourcepub fn apply_to_all(&mut self, f: &dyn Fn(T) -> T)
pub fn apply_to_all(&mut self, f: &dyn Fn(T) -> T)
Applies a function to all entries in this matrix, in place
Source§impl<R: Ring> Matrix<R>
impl<R: Ring> Matrix<R>
Sourcepub fn from_cols(columns: Vec<Matrix<R>>) -> Matrix<R>
pub fn from_cols(columns: Vec<Matrix<R>>) -> Matrix<R>
Constructs a matrix with the given columns
Sourcepub fn new(rows: usize, cols: usize) -> Matrix<R>
pub fn new(rows: usize, cols: usize) -> Matrix<R>
Constructs a matrix of all zeroes for a given dimension
Sourcepub fn get_diagonal(&self) -> Vec<R>
pub fn get_diagonal(&self) -> Vec<R>
Returns the diagonal of this matrix as a list
Sourcepub fn get_upperdiagonal(&self) -> Vec<R>
pub fn get_upperdiagonal(&self) -> Vec<R>
Returns the upper diagonal of this matrix as a list
Sourcepub fn inner_product(&self, other: &Matrix<R>) -> R
pub fn inner_product(&self, other: &Matrix<R>) -> R
Computes the inner-product of this vector with another vector
This operates in the entries in the flatmap of each matrix, so if the argument to this function are not proper vectors (i.e., they are matrices with both dimensions greater than 1) then the behavior here is not well-defined
Sourcepub fn l2_norm_squared(&self) -> R
pub fn l2_norm_squared(&self) -> R
The squared L2 norm of this vector
Sourcepub fn hadamard(&self, other: Matrix<R>) -> Matrix<R>
pub fn hadamard(&self, other: Matrix<R>) -> Matrix<R>
Computes the point-wise product of this and another matrix of the same dimension
Sourcepub fn identity(rows: usize, cols: usize) -> Matrix<R>
pub fn identity(rows: usize, cols: usize) -> Matrix<R>
Constructs the rows * cols identity matrix
Sourcepub fn from_diagonal(diagonal: Vec<R>) -> Matrix<R>
pub fn from_diagonal(diagonal: Vec<R>) -> Matrix<R>
Creates a diagonal matrix from a given diagonal
Sourcepub fn from_block_diagonal(blocks: Vec<Matrix<R>>) -> Matrix<R>
pub fn from_block_diagonal(blocks: Vec<Matrix<R>>) -> Matrix<R>
Creates a block-diagonal matrix from square blocks
Sourcepub fn from_bidiagonal(diagonal: Vec<R>, superdiagonal: Vec<R>) -> Matrix<R>
pub fn from_bidiagonal(diagonal: Vec<R>, superdiagonal: Vec<R>) -> Matrix<R>
Creates an upper bidiagonal matrix from a diagonal and superdiagonal
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Returns true if this matrix is the identity matrix
Source§impl<F: Field> Matrix<F>
impl<F: Field> Matrix<F>
Sourcepub fn is_orthogonal_to(&self, other: Matrix<F>) -> bool
pub fn is_orthogonal_to(&self, other: Matrix<F>) -> bool
Returns whether or not two vectors are orthogonal
Sourcepub fn is_orthogonal(&self) -> bool
pub fn is_orthogonal(&self) -> bool
Returns whether or not a matrix is orthogonal (meaning its columns are each orthogonal and of unit length)
Sourcepub fn proj_onto(&self, other: Matrix<F>) -> Matrix<F>
pub fn proj_onto(&self, other: Matrix<F>) -> Matrix<F>
Projects this vector onto another vector
Sourcepub fn gram_schmidt(&self) -> Matrix<F>
pub fn gram_schmidt(&self) -> Matrix<F>
Performs Gram-Schmidt Orthogonalization on a matrix, returning a matrix whose columns are orthogonal, and span the same column space as the original matrix. This does NOT normalize the GS vectors.
Trait Implementations§
Source§impl<R: Ring> AddAssign for Matrix<R>
impl<R: Ring> AddAssign for Matrix<R>
Source§fn add_assign(&mut self, rhs: Matrix<R>)
fn add_assign(&mut self, rhs: Matrix<R>)
+=
operation. Read moreSource§impl<F: Field> DivAssign<F> for Matrix<F>
impl<F: Field> DivAssign<F> for Matrix<F>
Source§fn div_assign(&mut self, rhs: F)
fn div_assign(&mut self, rhs: F)
/=
operation. Read moreSource§impl<R: Ring> MulAssign<R> for Matrix<R>
impl<R: Ring> MulAssign<R> for Matrix<R>
Source§fn mul_assign(&mut self, rhs: R)
fn mul_assign(&mut self, rhs: R)
*=
operation. Read moreSource§impl<R: Ring> MulAssign for Matrix<R>
impl<R: Ring> MulAssign for Matrix<R>
Source§fn mul_assign(&mut self, rhs: Matrix<R>)
fn mul_assign(&mut self, rhs: Matrix<R>)
Performs in-place multiplication, only valid on square matrices