pub struct Matrix<T: IsFloat + Debug + Copy + Clone> { /* private fields */ }Expand description
Generic dynamically-sized Matrix struct for the entire gpurs library.
Implementations§
Source§impl<T: IsFloat + Debug + Copy + Clone> Matrix<T>
impl<T: IsFloat + Debug + Copy + Clone> Matrix<T>
Sourcepub fn new(data: Vec<T>, rows: usize, cols: usize) -> Result<Matrix<T>>
pub fn new(data: Vec<T>, rows: usize, cols: usize) -> Result<Matrix<T>>
Create new matrix (includes error checking).
// This code will run, because rows * cols
// equals the number of elements in the data vector
let new_matrix: Matrix<f32> = Matrix::new(vec![0.0; 4], 2, 2)?;// This code will panic, because rows * cols
// does not equal the number of elements in the data vector
let new_matrix: Matrix<f32> = Matrix::new(vec![0.0; 4], 3, 3)?;Sourcepub fn get_rows(&self) -> usize
pub fn get_rows(&self) -> usize
Get number of rows in matrix.
let new_matrix: Matrix<f64> = Matrix::new(vec![0.0; 6], 3, 2)?;
assert_eq!(new_matrix.get_rows(), 3);Sourcepub fn all_rows(&self) -> RowMatIter<T>
pub fn all_rows(&self) -> RowMatIter<T>
Return iterator object full of every row in the matrix.
let new_matrix: Matrix<f32> = Matrix::new(vec![0.0; 6], 3, 2)?;
for row in new_matrix.all_rows() {
// Do something neat
}This does not return a mutable reference, so changing the row matrix spat out by the iterator does not change the underlying matrix.
Sourcepub fn get_cols(&self) -> usize
pub fn get_cols(&self) -> usize
Get number of cols in matrix.
let new_matrix: Matrix<f64> = Matrix::new(vec![0.0; 6], 3, 2)?;
assert_eq!(new_matrix.get_cols(), 2);Sourcepub fn all_cols(&self) -> ColMatIter<T>
pub fn all_cols(&self) -> ColMatIter<T>
Return iterator object full of every column in the matrix.
let new_matrix: Matrix<f32> = Matrix::new(vec![0.0; 6], 3, 2)?;
for col in new_matrix.all_cols() {
// Do something neat
}This does not return a mutable reference, so changing the column matrix spat out by the iterator does not change the underlying matrix.
Sourcepub fn get_data(&self) -> &[T]
pub fn get_data(&self) -> &[T]
Get matrix data in slice form.
let new_matrix: Matrix<f64> = Matrix::new(vec![0.0; 6], 3, 2)?;
assert_eq!(new_matrix.get_data(), [0.0; 6]);Sourcepub fn row_matrix(&self, row_idx: usize) -> Result<Matrix<T>>
pub fn row_matrix(&self, row_idx: usize) -> Result<Matrix<T>>
Get indexed row of matrix in matrix form.
let new_matrix: Matrix<f32> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let second_row: Matrix<f32> = Matrix::new(vec![3.0, 4.0], 1, 2)?;
assert_eq!(new_matrix.row_matrix(1)?.get_data(), second_row.get_data());Sourcepub fn row_vec(&self, row_idx: usize) -> Result<Vec<T>>
pub fn row_vec(&self, row_idx: usize) -> Result<Vec<T>>
Get indexed row of matrix in vector form.
let new_matrix: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
assert_eq!(new_matrix.row_vec(0)?, vec![1.0, 2.0]);Sourcepub fn col_matrix(&self, col_idx: usize) -> Result<Matrix<T>>
pub fn col_matrix(&self, col_idx: usize) -> Result<Matrix<T>>
Get indexed col of matrix in matrix form.
let new_matrix: Matrix<f32> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let second_col: Matrix<f32> = Matrix::new(vec![2.0, 4.0], 2, 1)?;
assert_eq!(new_matrix.col_matrix(1)?.get_data(), second_col.get_data());Sourcepub fn col_vec(&self, col_idx: usize) -> Result<Vec<T>>
pub fn col_vec(&self, col_idx: usize) -> Result<Vec<T>>
Get indexed col of matrix in vector form.
let new_matrix: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
assert_eq!(new_matrix.col_vec(0)?, vec![1.0, 3.0]);Sourcepub fn slice_index(&self, row_idcs: &[usize], col_idcs: &[usize]) -> Matrix<T>
pub fn slice_index(&self, row_idcs: &[usize], col_idcs: &[usize]) -> Matrix<T>
Index matrix using usize slices, outputing matrix of the index intersections.
Think of drawing lines across each selected row and down each selected column, then compiling the elements at their intersections into a new matrix.
let matrix_data: Vec<f32> = (1..=9).into_iter().map(|x| x as f32).collect::<Vec<f32>>();
let new_matrix: Matrix<f32> = Matrix::new(matrix_data, 3, 3)?;
let sliced_matrix: Matrix<f32> = new_matrix.slice_index(&[0, 1], &[0, 2]);
assert_eq!(sliced_matrix.get_data(), [1.0, 3.0, 4.0, 6.0]);Source§impl Matrix<f32>
impl Matrix<f32>
Sourcepub fn zeros(rows: usize, cols: usize) -> Matrix<f32>
pub fn zeros(rows: usize, cols: usize) -> Matrix<f32>
Create new matrix of zeros.
let zero_matrix: Matrix<f32> = Matrix::<f32>::zeros(2, 3);
assert_eq!(zero_matrix.get_data(), [0.0; 6]);Sourcepub fn ones(rows: usize, cols: usize) -> Matrix<f32>
pub fn ones(rows: usize, cols: usize) -> Matrix<f32>
Create new matrix of ones.
let ones_matrix: Matrix<f32> = Matrix::<f32>::ones(2, 3);
assert_eq!(ones_matrix.get_data(), [1.0; 6]);Sourcepub fn identity(dim_n: usize) -> Matrix<f32>
pub fn identity(dim_n: usize) -> Matrix<f32>
Create new identity matrix.
let identity_matrix: Matrix<f32> = Matrix::<f32>::identity(2);
assert_eq!(identity_matrix.get_data(), [1.0, 0.0, 0.0, 1.0]);Sourcepub fn elementwise(self, rhs: Matrix<f32>) -> Result<Matrix<f32>>
pub fn elementwise(self, rhs: Matrix<f32>) -> Result<Matrix<f32>>
Elementwise multiplication between two matrices. Matrices must be of the same size and shape.
let matrix_1: Matrix<f32> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let matrix_2: Matrix<f32> = Matrix::new(vec![2.0, 3.0, 4.0, 1.0], 2, 2)?;
let ew_product: Matrix<f32> = matrix_1.elementwise(matrix_2)?;
assert_eq!(ew_product.get_data(), [2.0, 6.0, 12.0, 4.0]);Sourcepub fn elementwise_divide(self, rhs: Matrix<f32>) -> Result<Matrix<f32>>
pub fn elementwise_divide(self, rhs: Matrix<f32>) -> Result<Matrix<f32>>
Elementwise division between two matrices. Matrices must be of the same size and shape.
let matrix_1: Matrix<f32> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let matrix_2: Matrix<f32> = Matrix::new(vec![2.0, 3.0, 4.0, 1.0], 2, 2)?;
let ew_division: Matrix<f32> = matrix_1.elementwise_divide(matrix_2)?;
assert_eq!(ew_division.get_data(), [0.5, 2.0/3.0, 0.75, 4.0]);Source§impl Matrix<f64>
impl Matrix<f64>
Sourcepub fn zeros(rows: usize, cols: usize) -> Matrix<f64>
pub fn zeros(rows: usize, cols: usize) -> Matrix<f64>
Create new matrix of zeros.
let zero_matrix: Matrix<f64> = Matrix::<f64>::zeros(2, 3);
assert_eq!(zero_matrix.get_data(), [0.0; 6]);Sourcepub fn ones(rows: usize, cols: usize) -> Matrix<f64>
pub fn ones(rows: usize, cols: usize) -> Matrix<f64>
Create new matrix of ones.
let ones_matrix: Matrix<f64> = Matrix::<f64>::ones(2, 3);
assert_eq!(ones_matrix.get_data(), [1.0; 6]);Sourcepub fn identity(dim_n: usize) -> Matrix<f64>
pub fn identity(dim_n: usize) -> Matrix<f64>
Create new identity matrix.
let identity_matrix: Matrix<f64> = Matrix::<f64>::identity(2);
assert_eq!(identity_matrix.get_data(), [1.0, 0.0, 0.0, 1.0]);Sourcepub fn elementwise(self, rhs: Matrix<f64>) -> Result<Matrix<f64>>
pub fn elementwise(self, rhs: Matrix<f64>) -> Result<Matrix<f64>>
Elementwise multiplication between two matrices. Matrices must be of the same size and shape.
let matrix_1: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let matrix_2: Matrix<f64> = Matrix::new(vec![2.0, 3.0, 4.0, 1.0], 2, 2)?;
let ew_product: Matrix<f64> = matrix_1.elementwise(matrix_2)?;
assert_eq!(ew_product.get_data(), [2.0, 6.0, 12.0, 4.0]);Sourcepub fn elementwise_divide(self, rhs: Matrix<f64>) -> Result<Matrix<f64>>
pub fn elementwise_divide(self, rhs: Matrix<f64>) -> Result<Matrix<f64>>
Elementwise division between two matrices. Matrices must be of the same size and shape.
let matrix_1: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let matrix_2: Matrix<f64> = Matrix::new(vec![2.0, 3.0, 4.0, 1.0], 2, 2)?;
let ew_division: Matrix<f64> = matrix_1.elementwise_divide(matrix_2)?;
assert_eq!(ew_division.get_data(), [0.5, 2.0/3.0, 0.75, 4.0]);Trait Implementations§
Source§impl Add<Matrix<f32>> for f32
Add matrix to float.
impl Add<Matrix<f32>> for f32
Add matrix to float.
let matrix: Matrix<f32> = Matrix::<f32>::ones(2, 3);
let new_matrix: Matrix<f32> = 1.0 + matrix;
assert_eq!(new_matrix.get_data(), [2.0; 6]);Source§impl Add<Matrix<f64>> for f64
Add matrix to float.
impl Add<Matrix<f64>> for f64
Add matrix to float.
let matrix: Matrix<f64> = Matrix::<f64>::ones(2, 3);
let new_matrix: Matrix<f64> = 1.0 + matrix;
assert_eq!(new_matrix.get_data(), [2.0; 6]);Source§impl Add<f32> for Matrix<f32>
Add float to matrix.
impl Add<f32> for Matrix<f32>
Add float to matrix.
let matrix: Matrix<f32> = Matrix::<f32>::zeros(3, 2);
let new_matrix: Matrix<f32> = matrix + 2.0;
assert_eq!(new_matrix.get_data(), [2.0; 6])Source§impl Add<f64> for Matrix<f64>
Add float to matrix.
impl Add<f64> for Matrix<f64>
Add float to matrix.
let matrix: Matrix<f64> = Matrix::<f64>::zeros(3, 2);
let new_matrix: Matrix<f64> = matrix + 2.0;
assert_eq!(new_matrix.get_data(), [2.0; 6]);Source§impl Add for Matrix<f32>
Add matrix to matrix.
Matrices must be of the same size and shape.
impl Add for Matrix<f32>
Add matrix to matrix. Matrices must be of the same size and shape.
let matrix_1: Matrix<f32> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let matrix_2: Matrix<f32> = Matrix::<f32>::ones(2, 2);
let new_matrix: Matrix<f32> = (matrix_1 + matrix_2)?;
assert_eq!(new_matrix.get_data(), [2.0, 3.0, 4.0, 5.0]);Source§impl Add for Matrix<f64>
Add matrix to matrix.
Matrices must be of the same size and shape.
impl Add for Matrix<f64>
Add matrix to matrix. Matrices must be of the same size and shape.
let matrix_1: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let matrix_2: Matrix<f64> = Matrix::<f64>::ones(2, 2);
let new_matrix: Matrix<f64> = (matrix_1 + matrix_2)?;
assert_eq!(new_matrix.get_data(), [2.0, 3.0, 4.0, 5.0]);Source§impl BooleanMatrixOperations<f32> for Matrix<f32>
impl BooleanMatrixOperations<f32> for Matrix<f32>
Source§fn equal(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
fn equal(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element == number
Source§fn less_than(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
fn less_than(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element < number
Source§fn less_equal(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
fn less_equal(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element <= number
Source§fn greater_than(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
fn greater_than(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element > number
Source§fn greater_equal(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
fn greater_equal(matrix: &Matrix<f32>, number: f32) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element >= number
Source§fn equal_mat(
left_matrix: &Matrix<f32>,
right_matrix: &Matrix<f32>,
) -> Result<Vec<bool>>
fn equal_mat( left_matrix: &Matrix<f32>, right_matrix: &Matrix<f32>, ) -> Result<Vec<bool>>
Return boolean vector with one element for each matrix element with values based on left_element == right_element
Returns error if left and right matrices have different dimensions
Source§fn less_than_mat(
left_matrix: &Matrix<f32>,
right_matrix: &Matrix<f32>,
) -> Result<Vec<bool>>
fn less_than_mat( left_matrix: &Matrix<f32>, right_matrix: &Matrix<f32>, ) -> Result<Vec<bool>>
Return boolean vector with one element for each matrix element with values based on left_element < right_element
Returns error if left and right matrices have different dimensions
Source§fn less_equal_mat(
left_matrix: &Matrix<f32>,
right_matrix: &Matrix<f32>,
) -> Result<Vec<bool>>
fn less_equal_mat( left_matrix: &Matrix<f32>, right_matrix: &Matrix<f32>, ) -> Result<Vec<bool>>
Return boolean vector with one element for each matrix element with values based on left_element <= right_element
Returns error if left and right matrices have different dimensions
Source§impl BooleanMatrixOperations<f64> for Matrix<f64>
impl BooleanMatrixOperations<f64> for Matrix<f64>
Source§fn equal(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
fn equal(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element == number
Source§fn less_than(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
fn less_than(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element < number
Source§fn less_equal(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
fn less_equal(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element <= number
Source§fn greater_than(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
fn greater_than(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element > number
Source§fn greater_equal(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
fn greater_equal(matrix: &Matrix<f64>, number: f64) -> Vec<bool>
Return boolean vector with one element for each matrix element with values based on element >= number
Source§fn equal_mat(
left_matrix: &Matrix<f64>,
right_matrix: &Matrix<f64>,
) -> Result<Vec<bool>>
fn equal_mat( left_matrix: &Matrix<f64>, right_matrix: &Matrix<f64>, ) -> Result<Vec<bool>>
Return boolean vector with one element for each matrix element with values based on left_element == right_element
Returns error if left and right matrices have different dimensions
Source§fn less_than_mat(
left_matrix: &Matrix<f64>,
right_matrix: &Matrix<f64>,
) -> Result<Vec<bool>>
fn less_than_mat( left_matrix: &Matrix<f64>, right_matrix: &Matrix<f64>, ) -> Result<Vec<bool>>
Return boolean vector with one element for each matrix element with values based on left_element < right_element
Returns error if left and right matrices have different dimensions
Source§fn less_equal_mat(
left_matrix: &Matrix<f64>,
right_matrix: &Matrix<f64>,
) -> Result<Vec<bool>>
fn less_equal_mat( left_matrix: &Matrix<f64>, right_matrix: &Matrix<f64>, ) -> Result<Vec<bool>>
Return boolean vector with one element for each matrix element with values based on left_element <= right_element
Returns error if left and right matrices have different dimensions
Source§impl<T: IsFloat + Debug + Copy + Clone> Display for Matrix<T>
Print matrix in a readable way.
impl<T: IsFloat + Debug + Copy + Clone> Display for Matrix<T>
Print matrix in a readable way.
Assume you have this matrix:
let matrix: Matrix<f32> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0, 5.0, 6.0], 2, 3)?;Printing using the debug logger as shown below would result in the following output:
println!("{:?}", matrix);
// This prints as
// Matrix { data: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0], rows: 2, cols: 3 }This implementation allows for standard printing which results in the following output:
println!("{}", matrix);
// This prints as
// [[1.0, 2.0, 3.0]
// [4.0, 5.0, 6.0]]Source§impl Div<Matrix<f32>> for f32
Divide float by matrix.
impl Div<Matrix<f32>> for f32
Divide float by matrix.
let matrix: Matrix<f32> = Matrix::<f32>::ones(2, 5);
let new_matrix: Matrix<f32> = 2.0 / matrix;
assert_eq!(new_matrix.get_data(), [2.0; 10])Source§impl Div<Matrix<f64>> for f64
Divide float by matrix.
impl Div<Matrix<f64>> for f64
Divide float by matrix.
let matrix: Matrix<f64> = Matrix::<f64>::ones(2, 5);
let new_matrix: Matrix<f64> = 2.0 / matrix;
assert_eq!(new_matrix.get_data(), [2.0; 10])Source§impl Div<f32> for Matrix<f32>
Divide matrix by float.
impl Div<f32> for Matrix<f32>
Divide matrix by float.
let matrix: Matrix<f32> = Matrix::<f32>::ones(2, 5);
let new_matrix: Matrix<f32> = matrix / 2.0;
assert_eq!(new_matrix.get_data(), [0.5; 10]);Source§impl Div<f64> for Matrix<f64>
Divide matrix by float.
impl Div<f64> for Matrix<f64>
Divide matrix by float.
let matrix: Matrix<f64> = Matrix::<f64>::ones(2, 5);
let new_matrix: Matrix<f64> = matrix / 2.0;
assert_eq!(new_matrix.get_data(), [0.5; 10]);Source§impl<T: IsFloat + Debug + Copy + Clone> Index<[usize; 2]> for Matrix<T>
Get value of matrix at index [row, col].
impl<T: IsFloat + Debug + Copy + Clone> Index<[usize; 2]> for Matrix<T>
Get value of matrix at index [row, col].
let row_idx: usize = 1;
let col_idx: usize = 0;
let indexed_value: f32 = matrix[[row_idx, col_idx]];Source§impl<T: IsFloat + Debug + Copy + Clone> IndexMut<[usize; 2]> for Matrix<T>
Modify value of matrix at index [row, col].
impl<T: IsFloat + Debug + Copy + Clone> IndexMut<[usize; 2]> for Matrix<T>
Modify value of matrix at index [row, col].
let mut matrix: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let row_idx: usize = 0;
let col_idx: usize = 1;
let new_value: f64 = 5.0;
matrix[[row_idx, col_idx]] = new_value;
assert_eq!(matrix.get_data(), [1.0, 5.0, 3.0, 4.0]);Source§impl MatrixUtilities<f32> for Matrix<f32>
impl MatrixUtilities<f32> for Matrix<f32>
Source§fn lu_decomp(matrix: &Matrix<f32>) -> Result<Matrix<f32>>
fn lu_decomp(matrix: &Matrix<f32>) -> Result<Matrix<f32>>
Perform partial LU decomposition of a matrix. This function returns a single matrix LU that is equivalent to L + U - I. This is designed primarily as a helper function for linear_solve_matrix. This function can return an error.
Source§fn linear_solve_matrix(
a_mat: &Matrix<f32>,
b_vec: &Matrix<f32>,
) -> Result<Matrix<f32>>
fn linear_solve_matrix( a_mat: &Matrix<f32>, b_vec: &Matrix<f32>, ) -> Result<Matrix<f32>>
Solve system of linear equations Ax=b. This will output x as a Matrix given A and b. This function can return an error.
Source§fn max(matrix: &Matrix<f32>) -> f32
fn max(matrix: &Matrix<f32>) -> f32
Find absolute maximum value of matrix. This will find and output the single maximum value across all elements in the matrix.
Source§fn axis_max(matrix: &Matrix<f32>, axis: Axis) -> Matrix<f32>
fn axis_max(matrix: &Matrix<f32>, axis: Axis) -> Matrix<f32>
Find maximum value of matrix along an axis. This will find the maximum value of each row or column and output them as a matrix.
Source§fn min(matrix: &Matrix<f32>) -> f32
fn min(matrix: &Matrix<f32>) -> f32
Find absolute minimum value of matrix. This will find and output the single minimum value across all elements in the matrix.
Source§fn axis_min(matrix: &Matrix<f32>, axis: Axis) -> Matrix<f32>
fn axis_min(matrix: &Matrix<f32>, axis: Axis) -> Matrix<f32>
Find minimum value of matrix along an axis. This will find the minimum value of each row or column and output them as a matrix.
Source§impl MatrixUtilities<f64> for Matrix<f64>
impl MatrixUtilities<f64> for Matrix<f64>
Source§fn lu_decomp(matrix: &Matrix<f64>) -> Result<Matrix<f64>>
fn lu_decomp(matrix: &Matrix<f64>) -> Result<Matrix<f64>>
Perform partial LU decomposition of a matrix. This function returns a single matrix LU that is equivalent to L + U - I. This is designed primarily as a helper function for linear_solve_matrix.
Source§fn linear_solve_matrix(
a_mat: &Matrix<f64>,
b_vec: &Matrix<f64>,
) -> Result<Matrix<f64>>
fn linear_solve_matrix( a_mat: &Matrix<f64>, b_vec: &Matrix<f64>, ) -> Result<Matrix<f64>>
Solve system of linear equations Ax=b. This will output x as a Matrix given A and b. This function can return an error.
Source§fn max(matrix: &Matrix<f64>) -> f64
fn max(matrix: &Matrix<f64>) -> f64
Find absolute maximum value of matrix. This will find and output the single maximum value across all elements in the matrix.
Source§fn axis_max(matrix: &Matrix<f64>, axis: Axis) -> Matrix<f64>
fn axis_max(matrix: &Matrix<f64>, axis: Axis) -> Matrix<f64>
Find maximum value of matrix along an axis. This will find the maximum value of each row or column and output them as a matrix.
Source§fn min(matrix: &Matrix<f64>) -> f64
fn min(matrix: &Matrix<f64>) -> f64
Find absolute minimum value of matrix. This will find the minimum value of each row or column and output them as a matrix.
Source§fn axis_min(matrix: &Matrix<f64>, axis: Axis) -> Matrix<f64>
fn axis_min(matrix: &Matrix<f64>, axis: Axis) -> Matrix<f64>
Find minimum value of matrix along an axis.
Source§impl Mul<Matrix<f32>> for f32
Multiply float by matrix.
impl Mul<Matrix<f32>> for f32
Multiply float by matrix.
let matrix: Matrix<f32> = Matrix::<f32>::ones(2, 5);
let new_matrix: Matrix<f32> = 8.0 * matrix;
assert_eq!(new_matrix.get_data(), [8.0; 10]);Source§impl Mul<Matrix<f64>> for f64
Multiply float by matrix.
impl Mul<Matrix<f64>> for f64
Multiply float by matrix.
let matrix: Matrix<f64> = Matrix::<f64>::ones(2, 5);
let new_matrix: Matrix<f64> = 8.0 * matrix;
assert_eq!(new_matrix.get_data(), [8.0; 10]);Source§impl Mul<f32> for Matrix<f32>
Multiply matrix by float.
impl Mul<f32> for Matrix<f32>
Multiply matrix by float.
let matrix: Matrix<f32> = Matrix::<f32>::ones(4, 3);
let new_matrix: Matrix<f32> = matrix * 5.0;
assert_eq!(new_matrix.get_data(), [5.0; 12]);Source§impl Mul<f64> for Matrix<f64>
Multiply matrix by float.
impl Mul<f64> for Matrix<f64>
Multiply matrix by float.
let matrix: Matrix<f64> = Matrix::<f64>::ones(4, 3);
let new_matrix: Matrix<f64> = matrix * 5.0;
assert_eq!(new_matrix.get_data(), [5.0; 12]);Source§impl Mul for Matrix<f32>
Multiply matrix by matrix.
impl Mul for Matrix<f32>
Multiply matrix by matrix.
Number of columns in the left matrix must equal the number of rows in the right matrix. The shape of the resultant matrix will be (left rows) by (right cols)
The value at every [i, j] index of the resultant matrix is equal to the dot product of the i-th row of the left matrix and the j-th col of the right matrix.
let left_matrix: Matrix<f32> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let right_matrix: Matrix<f32> = Matrix::new(vec![6.0, 1.0, 5.0, 2.0, 4.0, 3.0], 2, 3)?;
let product: Matrix<f32> = (left_matrix * right_matrix)?;
assert_eq!(product.get_data(), [10.0, 9.0, 11.0, 26.0, 19.0, 27.0]);Source§impl Mul for Matrix<f64>
Multiply matrix by matrix.
impl Mul for Matrix<f64>
Multiply matrix by matrix.
Number of columns in the left matrix must equal the number of rows in the right matrix. The shape of the resultant matrix will be (left rows) by (right cols)
The value at every [i, j] index of the resultant matrix is equal to the dot product of the i-th row of the left matrix and the j-th col of the right matrix.
let left_matrix: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let right_matrix: Matrix<f64> = Matrix::new(vec![6.0, 1.0, 5.0, 2.0, 4.0, 3.0], 2, 3)?;
let product: Matrix<f64> = (left_matrix * right_matrix)?;
assert_eq!(product.get_data(), [10.0, 9.0, 11.0, 26.0, 19.0, 27.0]);Source§impl Neg for Matrix<f32>
Negate matrix.
impl Neg for Matrix<f32>
Negate matrix.
let matrix: Matrix<f32> = Matrix::<f32>::ones(4, 4);
let negated_matrix: Matrix<f32> = -matrix;
assert_eq!(negated_matrix.get_data(), [-1.0; 16]);Source§impl Neg for Matrix<f64>
Negate matrix.
impl Neg for Matrix<f64>
Negate matrix.
let matrix: Matrix<f64> = Matrix::<f64>::ones(4, 4);
let negated_matrix: Matrix<f64> = -matrix;
assert_eq!(negated_matrix.get_data(), [-1.0; 16]);Source§impl ReferenceOperations<f32> for Matrix<f32>
impl ReferenceOperations<f32> for Matrix<f32>
Source§fn ref_add(left: &Matrix<f32>, right: &Matrix<f32>) -> Result<Matrix<f32>>
fn ref_add(left: &Matrix<f32>, right: &Matrix<f32>) -> Result<Matrix<f32>>
Add one matrix to another matrix. Inputs are immutable references unlike the basic addition operator.
Source§fn ref_neg(mat: &Matrix<f32>) -> Matrix<f32>
fn ref_neg(mat: &Matrix<f32>) -> Matrix<f32>
Negate a matrix. Input is an immutable reference unlike the basic negation operator.
Source§fn ref_sub(left: &Matrix<f32>, right: &Matrix<f32>) -> Result<Matrix<f32>>
fn ref_sub(left: &Matrix<f32>, right: &Matrix<f32>) -> Result<Matrix<f32>>
Subtract one matrix from another matrix. Inputs are immutable references unlike the basic subtraction operator.
Source§fn ref_mul(left: &Matrix<f32>, right: &Matrix<f32>) -> Result<Matrix<f32>>
fn ref_mul(left: &Matrix<f32>, right: &Matrix<f32>) -> Result<Matrix<f32>>
Multiply one matrix by another matrix. Inputs are immutable references unlike the basic multiplication operator.
Source§impl ReferenceOperations<f64> for Matrix<f64>
impl ReferenceOperations<f64> for Matrix<f64>
Source§fn ref_add(left: &Matrix<f64>, right: &Matrix<f64>) -> Result<Matrix<f64>>
fn ref_add(left: &Matrix<f64>, right: &Matrix<f64>) -> Result<Matrix<f64>>
Add one matrix to another matrix. Inputs are immutable references unlike the basic addition operator.
Source§fn ref_neg(mat: &Matrix<f64>) -> Matrix<f64>
fn ref_neg(mat: &Matrix<f64>) -> Matrix<f64>
Negate a matrix. Input is an immutable reference unlike the basic negation operator.
Source§fn ref_sub(left: &Matrix<f64>, right: &Matrix<f64>) -> Result<Matrix<f64>>
fn ref_sub(left: &Matrix<f64>, right: &Matrix<f64>) -> Result<Matrix<f64>>
Subtract one matrix from another matrix. Inputs are immutable references unlike the basic subtraction operator.
Source§fn ref_mul(left: &Matrix<f64>, right: &Matrix<f64>) -> Result<Matrix<f64>>
fn ref_mul(left: &Matrix<f64>, right: &Matrix<f64>) -> Result<Matrix<f64>>
Multiply one matrix by another matrix. Inputs are immutable references unlike the basic multiplication operator.
Source§impl Sub<Matrix<f32>> for f32
Subtract matrix from float.
impl Sub<Matrix<f32>> for f32
Subtract matrix from float.
let matrix: Matrix<f32> = Matrix::<f32>::ones(2, 3);
let new_matrix: Matrix<f32> = 1.0 - matrix;
assert_eq!(new_matrix.get_data(), [0.0; 6]);Source§impl Sub<Matrix<f64>> for f64
Subtract matrix from float.
impl Sub<Matrix<f64>> for f64
Subtract matrix from float.
let matrix: Matrix<f64> = Matrix::<f64>::ones(2, 3);
let new_matrix: Matrix<f64> = 1.0 - matrix;
assert_eq!(new_matrix.get_data(), [0.0; 6]);Source§impl Sub<f32> for Matrix<f32>
Subtract float from matrix.
impl Sub<f32> for Matrix<f32>
Subtract float from matrix.
let matrix: Matrix<f32> = Matrix::<f32>::zeros(3, 2);
let new_matrix: Matrix<f32> = matrix - 2.0;
assert_eq!(new_matrix.get_data(), [-2.0; 6]);Source§impl Sub<f64> for Matrix<f64>
Subtract float from matrix.
impl Sub<f64> for Matrix<f64>
Subtract float from matrix.
let matrix: Matrix<f64> = Matrix::<f64>::zeros(3, 2);
let new_matrix: Matrix<f64> = matrix - 2.0;
assert_eq!(new_matrix.get_data(), [-2.0; 6]);Source§impl Sub for Matrix<f32>
Subtract matrix from matrix.
Matrices must be of the same size and shape.
impl Sub for Matrix<f32>
Subtract matrix from matrix. Matrices must be of the same size and shape.
let matrix_1: Matrix<f32> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let matrix_2: Matrix<f32> = Matrix::<f32>::ones(2, 2);
let new_matrix: Matrix<f32> = (matrix_1 - matrix_2)?;
assert_eq!(new_matrix.get_data(), [0.0, 1.0, 2.0, 3.0]);Source§impl Sub for Matrix<f64>
Subtract matrix from matrix.
Matrices must be of the same size and shape.
impl Sub for Matrix<f64>
Subtract matrix from matrix. Matrices must be of the same size and shape.
let matrix_1: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
let matrix_2: Matrix<f64> = Matrix::<f64>::ones(2, 2);
let new_matrix: Matrix<f64> = (matrix_1 - matrix_2)?;
assert_eq!(new_matrix.get_data(), [0.0, 1.0, 2.0, 3.0]);