pub struct Matrix<T> {
pub data: Vec<T>,
pub row_size: usize,
pub col_size: usize,
}Expand description
MxN Matrix
Fields§
§data: Vec<T>§row_size: usize§col_size: usizeImplementations§
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn leaky_relu(&self, alpha: T) -> Matrix<T>
pub fn leaky_relu(&self, alpha: T) -> Matrix<T>
Apply the Leaky ReLU activation function onto a Matrix
Sourcepub fn relu_backward(&self) -> Matrix<T>
pub fn relu_backward(&self) -> Matrix<T>
Apply backward pass for the ReLU activation function onto a Matrix
Source§impl<T: Default + Clone> Matrix<T>
impl<T: Default + Clone> Matrix<T>
Sourcepub fn new(row_size: usize, col_size: usize) -> Self
pub fn new(row_size: usize, col_size: usize) -> Self
Construct a new non-empty and sized Matrix
Sourcepub fn new_random(row_size: usize, col_size: usize) -> Selfwhere
T: Random,
pub fn new_random(row_size: usize, col_size: usize) -> Selfwhere
T: Random,
Construct a new non-empty and sized Matrix with random values of T
Sourcepub fn get(&self, row: usize, col: usize) -> Option<&T>
pub fn get(&self, row: usize, col: usize) -> Option<&T>
Try to get a reference to the value at a given row and column from the matrix
Sourcepub fn get_diagonal(&self) -> Vec<T>
pub fn get_diagonal(&self) -> Vec<T>
Get a vector of the diagonal elements of the matrix
Sourcepub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>
pub fn get_mut(&mut self, row: usize, col: usize) -> Option<&mut T>
Try to get a mutable reference to the value at a given row and column from the matrix
Sourcepub fn set(&mut self, row: usize, column: usize, value: T) -> bool
pub fn set(&mut self, row: usize, column: usize, value: T) -> bool
Try to set a value at a given row and column in the matrix
Sourcepub fn try_get_column(&self, column: usize) -> Option<Vec<T>>
pub fn try_get_column(&self, column: usize) -> Option<Vec<T>>
Try to get all the values for a given column
NOTE: If you pass a column value larger than the number of columns this function will return None.
Sourcepub fn try_get_row(&self, row: usize) -> Option<Vec<T>>
pub fn try_get_row(&self, row: usize) -> Option<Vec<T>>
Try to get all the values for a given row
NOTE: If you pass a row value larger than the number of rows this function will return None.
Sourcepub fn from_columns(cols: Vec<Vec<T>>) -> Matrix<T>
pub fn from_columns(cols: Vec<Vec<T>>) -> Matrix<T>
Create a Matrix from a columns (vec of vec)
Sourcepub fn sub_matrix(&self, skip_row: usize, skip_col: usize) -> Matrix<T>
pub fn sub_matrix(&self, skip_row: usize, skip_col: usize) -> Matrix<T>
Create a sub matrix with a specific row and column to exclude
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn scalar_multiply(&self, scalar: T) -> Matrix<T>
pub fn scalar_multiply(&self, scalar: T) -> Matrix<T>
Multiply a matrix by a single number (scalar) NOTE: The scalar type MUST match the matrix type.
Sourcepub fn multiply(&self, multiplier: &Matrix<T>) -> Option<Matrix<T>>
pub fn multiply(&self, multiplier: &Matrix<T>) -> Option<Matrix<T>>
Multiply Matrix with another Matrix using standard matrix multiplication
NOTE: The matrices inner dimensions MUST match else returns None
Sourcepub fn vector_multiply(&self, multiplier: &[T]) -> Option<Vec<T>>
pub fn vector_multiply(&self, multiplier: &[T]) -> Option<Vec<T>>
Multiply the Matrix by a vector
NOTE: The vectors length MUST match the vector columns, else returns None
Sourcepub fn determinant(&self) -> Option<T>
pub fn determinant(&self) -> Option<T>
Compute a unique determinant for a Matrix
NOTE: Only computable for square (M x M) matrices.
NOTE: The determinant is 0 for a Matrix with rank r < M (non-invertable).
Source§impl<T> Matrix<T>
impl<T> Matrix<T>
Sourcepub fn frobenius_norm(&self) -> f64
pub fn frobenius_norm(&self) -> f64
Compute the frobenius norm of a Matrix