Matrix

Struct Matrix 

Source
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>

Source

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)?;
Source

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);
Source

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.

Source

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);
Source

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.

Source

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]);
Source

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());
Source

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]);
Source

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());
Source

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]);
Source

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

pub fn transpose(&self) -> Matrix<T>

Matrix transpose

let new_matrix: Matrix<f64> = Matrix::new(vec![1.0, 2.0, 3.0, 4.0], 2, 2)?;
 
assert_eq!(new_matrix.transpose().get_data(), [1.0, 3.0, 2.0, 4.0]);
Source§

impl Matrix<f32>

Source

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]);
Source

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]);
Source

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]);
Source

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]);
Source

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

pub fn lindex(&self, linear_index: usize) -> f32

Returns index of flattened array. Shorthand for matrix.get_data()[linear_index].

Source§

impl Matrix<f64>

Source

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]);
Source

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]);
Source

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]);
Source

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]);
Source

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]);
Source

pub fn lindex(&self, linear_index: usize) -> f64

Returns index of flattened array. Shorthand for matrix.get_data()[linear_index].

Trait Implementations§

Source§

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§

type Output = Matrix<f32>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix<f32>) -> Matrix<f32>

Performs the + operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix<f64>) -> Matrix<f64>

Performs the + operation. Read more
Source§

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§

type Output = Matrix<f32>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f32) -> Matrix<f32>

Performs the + operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Matrix<f64>

Performs the + operation. Read more
Source§

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§

type Output = Result<Matrix<f32>, Jeeperr>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix<f32>) -> Result<Matrix<f32>>

Performs the + operation. Read more
Source§

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§

type Output = Result<Matrix<f64>, Jeeperr>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Matrix<f64>) -> Result<Matrix<f64>>

Performs the + operation. Read more
Source§

impl BooleanMatrixOperations<f32> for Matrix<f32>

Source§

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>

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>

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>

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>

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>>

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>>

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>>

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 greater_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 greater_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>

Source§

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>

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>

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>

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>

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>>

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>>

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>>

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 greater_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 greater_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: Clone + IsFloat + Debug + Copy + Clone> Clone for Matrix<T>

Source§

fn clone(&self) -> Matrix<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + IsFloat + Debug + Copy + Clone> Debug for Matrix<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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§

type Output = Matrix<f32>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Matrix<f32>) -> Matrix<f32>

Performs the / operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Matrix<f64>) -> Matrix<f64>

Performs the / operation. Read more
Source§

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§

type Output = Matrix<f32>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f32) -> Matrix<f32>

Performs the / operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> Matrix<f64>

Performs the / operation. Read more
Source§

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§

type Output = T

The returned type after indexing.
Source§

fn index(&self, idx: [usize; 2]) -> &T

Performs the indexing (container[index]) operation. Read more
Source§

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§

fn index_mut(&mut self, index: [usize; 2]) -> &mut T

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl MatrixUtilities<f32> for Matrix<f32>

Source§

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>>

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

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>

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

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>

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§

fn sum(matrix: &Matrix<f32>) -> f32

Find sum of all elements in a matrix.

Source§

fn axis_sum(matrix: &Matrix<f32>, axis: Axis) -> Matrix<f32>

Sum elements of a matrix along rows or columns, returning a column or row matrix.

Source§

fn concatenate(matrices: &[Matrix<f32>], axis: Axis) -> Result<Matrix<f32>>

Concatenate slice of matrices together along an axis. Think of this as “stacking” the matrices together either top to bottom (Axis::Row) or left to right (Axis::Col)

Source§

impl MatrixUtilities<f64> for Matrix<f64>

Source§

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>>

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

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>

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

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>

Find minimum value of matrix along an axis.

Source§

fn sum(matrix: &Matrix<f64>) -> f64

Find sum of all elements in a matrix.

Source§

fn axis_sum(matrix: &Matrix<f64>, axis: Axis) -> Matrix<f64>

Sum elements of a matrix along rows or columns, returning a column or row matrix.

Source§

fn concatenate(matrices: &[Matrix<f64>], axis: Axis) -> Result<Matrix<f64>>

Concatenate slice of matrices together along an axis. Think of this as “stacking” the matrices together either top to bottom (Axis::Row) or left to right (Axis::Col)

Source§

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§

type Output = Matrix<f32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix<f32>) -> Matrix<f32>

Performs the * operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix<f64>) -> Matrix<f64>

Performs the * operation. Read more
Source§

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§

type Output = Matrix<f32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f32) -> Matrix<f32>

Performs the * operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Matrix<f64>

Performs the * operation. Read more
Source§

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§

type Output = Result<Matrix<f32>, Jeeperr>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix<f32>) -> Result<Matrix<f32>>

Performs the * operation. Read more
Source§

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§

type Output = Result<Matrix<f64>, Jeeperr>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Matrix<f64>) -> Result<Matrix<f64>>

Performs the * operation. Read more
Source§

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§

type Output = Matrix<f32>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Matrix<f32>

Performs the unary - operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Matrix<f64>

Performs the unary - operation. Read more
Source§

impl ReferenceOperations<f32> for Matrix<f32>

Source§

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>

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>>

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>>

Multiply one matrix by another matrix. Inputs are immutable references unlike the basic multiplication operator.

Source§

fn ref_ewm(left: &Matrix<f32>, right: &Matrix<f32>) -> Result<Matrix<f32>>

Multiply two matrices elementwise. Inputs are immutable references unlike the basic elementwise function.

Source§

fn ref_ewd(left: &Matrix<f32>, right: &Matrix<f32>) -> Result<Matrix<f32>>

Divide two matrices elementwise. Inputs are immutable references unlike the basic elementwise_divide function.

Source§

impl ReferenceOperations<f64> for Matrix<f64>

Source§

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>

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>>

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>>

Multiply one matrix by another matrix. Inputs are immutable references unlike the basic multiplication operator.

Source§

fn ref_ewm(left: &Matrix<f64>, right: &Matrix<f64>) -> Result<Matrix<f64>>

Multiply two matrices elementwise. Inputs are immutable references unlike the basic elementwise function.

Source§

fn ref_ewd(left: &Matrix<f64>, right: &Matrix<f64>) -> Result<Matrix<f64>>

Divide two matrices elementwise. Inputs are immutable references unlike the basic elementwise_divide function.

Source§

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§

type Output = Matrix<f32>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix<f32>) -> Matrix<f32>

Performs the - operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix<f64>) -> Matrix<f64>

Performs the - operation. Read more
Source§

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§

type Output = Matrix<f32>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f32) -> Matrix<f32>

Performs the - operation. Read more
Source§

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§

type Output = Matrix<f64>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Matrix<f64>

Performs the - operation. Read more
Source§

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§

type Output = Result<Matrix<f32>, Jeeperr>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix<f32>) -> Result<Matrix<f32>>

Performs the - operation. Read more
Source§

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]);
Source§

type Output = Result<Matrix<f64>, Jeeperr>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Matrix<f64>) -> Result<Matrix<f64>>

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Matrix<T>

§

impl<T> RefUnwindSafe for Matrix<T>
where T: RefUnwindSafe,

§

impl<T> Send for Matrix<T>
where T: Send,

§

impl<T> Sync for Matrix<T>
where T: Sync,

§

impl<T> Unpin for Matrix<T>
where T: Unpin,

§

impl<T> UnwindSafe for Matrix<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.