pub struct Matrix {
pub nrows: usize,
pub ncols: usize,
/* private fields */
}Expand description
Matrix struct.
Fields§
§nrows: usize§ncols: usizeImplementations§
Source§impl Matrix
impl Matrix
pub fn empty() -> Self
Sourcepub fn empty_size(nrows: usize, ncols: usize) -> Self
pub fn empty_size(nrows: usize, ncols: usize) -> Self
Make an empty matrix with a given size
Sourcepub fn is_symmetric(&self) -> bool
pub fn is_symmetric(&self) -> bool
Check whether the matrix is symmetric.
Sourcepub fn close_to(&self, other: &Matrix, tol: f64) -> bool
pub fn close_to(&self, other: &Matrix, tol: f64) -> bool
Check whether a matrix is close to another matrix within some tolerance.
Sourcepub fn is_positive_definite(&self) -> bool
pub fn is_positive_definite(&self) -> bool
Check whether the matrix is positive definite.
Sourcepub fn forward_substitution(&self, b: &[f64]) -> Vector
pub fn forward_substitution(&self, b: &[f64]) -> Vector
Solve a matrix equation of the form Lx=b, where L is a lower triangular matrix. See the Wikipedia page.
Sourcepub fn backward_substitution(&self, b: &[f64]) -> Vector
pub fn backward_substitution(&self, b: &[f64]) -> Vector
Solve a matrix equation of the form Ux=b, where U is an upper triangular matrix. See the Wikipedia page.
Sourcepub fn cholesky(&self) -> Matrix
pub fn cholesky(&self) -> Matrix
Return the Cholesky decomposition of the matrix. Resulting matrix is lower triangular.
pub fn lu(&self) -> (Matrix, Vec<i32>)
Sourcepub fn lu_det(&self, piv: &[i32]) -> f64
pub fn lu_det(&self, piv: &[i32]) -> f64
Calculates the determinant of an LU decomposed matrix.
Sourcepub fn is_upper_triangular(&self) -> bool
pub fn is_upper_triangular(&self) -> bool
Check whether the matrix is upper triangular (i.e., all the entries below the diagonal are 0).
Sourcepub fn is_lower_triangular(&self) -> bool
pub fn is_lower_triangular(&self) -> bool
Check whether the matrix is lower triangular (i.e., all the entries above the diagonal are 0).
Sourcepub fn new<T>(data: T, nrows: i32, ncols: i32) -> Self
pub fn new<T>(data: T, nrows: i32, ncols: i32) -> Self
Make a new matrix with the given number of rows and columns.
Sourcepub fn reshape_mut(&mut self, nrows: i32, ncols: i32) -> &mut Self
pub fn reshape_mut(&mut self, nrows: i32, ncols: i32) -> &mut Self
Reshape the matrix in-place. A size of -1 in either the rows or the columns means that the size
for that dimension will be automatically determined if possible.
Sourcepub fn reshape(&self, nrows: i32, ncols: i32) -> Self
pub fn reshape(&self, nrows: i32, ncols: i32) -> Self
Reshape the matrix. A size of -1 in either the rows or the columns means that the size
for that dimension will be automatically determined if possible.
Sourcepub fn apply_along_row<F>(&mut self, row: usize, f: F)
pub fn apply_along_row<F>(&mut self, row: usize, f: F)
Apply a closure to every element in a row. The closure should take a value and return the value to replace it with.
Sourcepub fn apply_along_col<F>(&mut self, col: usize, f: F)
pub fn apply_along_col<F>(&mut self, col: usize, f: F)
Apply a closure to every element in a row.
Sourcepub fn get_row_as_vector(&self, row: usize) -> Vector
pub fn get_row_as_vector(&self, row: usize) -> Vector
Return a copy of the row of the matrix as a Vector.
Sourcepub fn get_col_as_vector(&self, col: usize) -> Vector
pub fn get_col_as_vector(&self, col: usize) -> Vector
Return a copy of the column of the matrix as a Vector.
pub fn flat_idx(&self, idx: usize) -> f64
pub fn flat_idx_replace(&mut self, idx: usize, val: f64) -> &mut Self
Sourcepub fn data_mut(&mut self) -> &mut Vector
pub fn data_mut(&mut self) -> &mut Vector
Return a mutable reference to the underlying Vector holding the data.
Sourcepub fn hcat(&self, other: Self) -> Self
pub fn hcat(&self, other: Self) -> Self
Horizontal concatenation of matrices. Adds other to the right of the calling matrix.
Sourcepub fn vcat(&self, other: Self) -> Self
pub fn vcat(&self, other: Self) -> Self
Vertical concatenation of matrices. Adds other below the calling matrix.
Source§impl Matrix
impl Matrix
Sourcepub fn to_radians(&self) -> Self
pub fn to_radians(&self) -> Self
Apply the f64 operation to_radians element-wise to the matrix.
Source§impl Matrix
impl Matrix
Sourcepub fn to_degrees(&self) -> Self
pub fn to_degrees(&self) -> Self
Apply the f64 operation to_degrees element-wise to the matrix.
Source§impl Matrix
impl Matrix
pub fn norm(&self) -> f64
pub fn max(&self) -> f64
pub fn mean(&self) -> f64
pub fn min(&self) -> f64
pub fn std(&self) -> f64
pub fn sum(&self) -> f64
pub fn prod(&self) -> f64
pub fn var(&self) -> f64
pub fn sample_std(&self) -> f64
pub fn sample_var(&self) -> f64
Trait Implementations§
Source§impl AddAssign<&Matrix> for Matrix
impl AddAssign<&Matrix> for Matrix
Source§fn add_assign(&mut self, other: &Matrix)
fn add_assign(&mut self, other: &Matrix)
+= operation. Read moreSource§impl AddAssign<f64> for Matrix
impl AddAssign<f64> for Matrix
Source§fn add_assign(&mut self, other: f64)
fn add_assign(&mut self, other: f64)
+= operation. Read moreSource§impl AddAssign for Matrix
impl AddAssign for Matrix
Source§fn add_assign(&mut self, other: Matrix)
fn add_assign(&mut self, other: Matrix)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for Matrix
impl<'de> Deserialize<'de> for Matrix
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl DivAssign<&Matrix> for Matrix
impl DivAssign<&Matrix> for Matrix
Source§fn div_assign(&mut self, other: &Matrix)
fn div_assign(&mut self, other: &Matrix)
/= operation. Read moreSource§impl DivAssign<f64> for Matrix
impl DivAssign<f64> for Matrix
Source§fn div_assign(&mut self, other: f64)
fn div_assign(&mut self, other: f64)
/= operation. Read moreSource§impl DivAssign for Matrix
impl DivAssign for Matrix
Source§fn div_assign(&mut self, other: Matrix)
fn div_assign(&mut self, other: Matrix)
/= operation. Read moreSource§impl Dot<&Matrix, Matrix> for &Matrix
impl Dot<&Matrix, Matrix> for &Matrix
Source§impl Dot<&Matrix, Matrix> for Matrix
impl Dot<&Matrix, Matrix> for Matrix
Source§impl Dot<&Matrix, Vector> for &Vector
impl Dot<&Matrix, Vector> for &Vector
Source§impl Dot<&Matrix, Vector> for Vector
impl Dot<&Matrix, Vector> for Vector
Source§impl Dot<&Vector, Vector> for &Matrix
impl Dot<&Vector, Vector> for &Matrix
Source§impl Dot<&Vector, Vector> for Matrix
impl Dot<&Vector, Vector> for Matrix
Source§impl Dot<Matrix, Matrix> for &Matrix
impl Dot<Matrix, Matrix> for &Matrix
Source§impl Dot<Matrix, Matrix> for Matrix
impl Dot<Matrix, Matrix> for Matrix
Source§impl Dot<Matrix, Vector> for &Vector
impl Dot<Matrix, Vector> for &Vector
Source§impl Dot<Matrix, Vector> for Vector
impl Dot<Matrix, Vector> for Vector
Source§impl Dot<Vector, Vector> for &Matrix
impl Dot<Vector, Vector> for &Matrix
Source§impl Dot<Vector, Vector> for Matrix
impl Dot<Vector, Vector> for Matrix
Source§impl<'a> IntoIterator for &'a Matrix
impl<'a> IntoIterator for &'a Matrix
Source§impl<'a> IntoIterator for &'a mut Matrix
impl<'a> IntoIterator for &'a mut Matrix
Source§impl MulAssign<&Matrix> for Matrix
impl MulAssign<&Matrix> for Matrix
Source§fn mul_assign(&mut self, other: &Matrix)
fn mul_assign(&mut self, other: &Matrix)
*= operation. Read moreSource§impl MulAssign<f64> for Matrix
impl MulAssign<f64> for Matrix
Source§fn mul_assign(&mut self, other: f64)
fn mul_assign(&mut self, other: f64)
*= operation. Read moreSource§impl MulAssign for Matrix
impl MulAssign for Matrix
Source§fn mul_assign(&mut self, other: Matrix)
fn mul_assign(&mut self, other: Matrix)
*= operation. Read moreSource§impl Solve<Vector> for Matrix
impl Solve<Vector> for Matrix
Source§fn lu_solve(&self, pivots: &[i32], system: &Vector) -> Vector
fn lu_solve(&self, pivots: &[i32], system: &Vector) -> Vector
Solve the linear system Ax = b given a LU decomposed matrix A. The first argument should be a tuple, where the first element is the LU decomposed matrix and the second element is the pivots P.
Source§fn solve(&self, system: &Vector) -> Vector
fn solve(&self, system: &Vector) -> Vector
Solve the linear system Ax = b using LU decomposition.
fn cholesky_solve(&self, system: &Vector) -> Vector
Source§impl SubAssign<&Matrix> for Matrix
impl SubAssign<&Matrix> for Matrix
Source§fn sub_assign(&mut self, other: &Matrix)
fn sub_assign(&mut self, other: &Matrix)
-= operation. Read more