Struct rusty_machine::linalg::Matrix
[−]
pub struct Matrix<T> { /* fields omitted */ }
The Matrix
struct.
Can be instantiated with any type.
Methods
impl<T> Matrix<T> where T: Any + Float
impl<T> Matrix<T> where T: Any + Float
impl<T> Matrix<T> where T: Any + Float
fn bidiagonal_decomp(self) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
Converts matrix to bidiagonal form
Returns (B, U, V), where B is bidiagonal and self = U B V_T
.
Note that if self
has self.rows() > self.cols()
the matrix will
be transposed and then reduced - this will lead to a sub-diagonal instead
of super-diagonal.
Failures
- The matrix cannot be reduced to bidiagonal form.
impl<T> Matrix<T> where T: Any + Signed + Float
fn svd(self) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
Singular Value Decomposition
Computes the SVD using the Golub-Reinsch algorithm.
Returns Σ, U, V, such that self
= U Σ VT. Σ is a diagonal matrix whose elements
correspond to the non-negative singular values of the matrix. The singular values are ordered in
non-increasing order. U and V have orthonormal columns, and each column represents the
left and right singular vectors for the corresponding singular value in Σ, respectively.
If self
has M rows and N columns, the dimensions of the returned matrices
are as follows.
If M >= N:
Σ
: N x NU
: M x NV
: N x N
If M < N:
Σ
: M x MU
: M x MV
: N x M
Note: This version of the SVD is sometimes referred to as the 'economy SVD'.
Failures
This function may fail in some cases. The current decomposition whilst being efficient is fairly basic. Hopefully the algorithm can be made not to fail in the near future.
impl<T> Matrix<T> where T: Any + Float
fn upper_hessenberg(self) -> Result<Matrix<T>, Error>
Returns H, where H is the upper hessenberg form.
If the transformation matrix is also required, you should
use upper_hess_decomp
.
Examples
use rulinalg::matrix::Matrix; let a = Matrix::new(4,4,vec![2.,0.,1.,1.,2.,0.,1.,2.,1.,2.,0.,0.,2.,0.,1.,1.]); let h = a.upper_hessenberg(); println!("{:?}", h.expect("Could not get upper Hessenberg form.").data());
Panics
- The matrix is not square.
Failures
- The matrix cannot be reduced to upper hessenberg form.
fn upper_hess_decomp(self) -> Result<(Matrix<T>, Matrix<T>), Error>
Returns (U,H), where H is the upper hessenberg form and U is the unitary transform matrix.
Note: The current transform matrix seems broken...
Examples
use rulinalg::matrix::{Matrix, BaseMatrix}; let a = Matrix::new(3,3,vec![1.,2.,3.,4.,5.,6.,7.,8.,9.]); // u is the transform, h is the upper hessenberg form. let (u,h) = a.clone().upper_hess_decomp().expect("This matrix should decompose!"); println!("The hess : {:?}", h.data()); println!("Manual hess : {:?}", (u.transpose() * a * u).data());
Panics
- The matrix is not square.
Failures
- The matrix cannot be reduced to upper hessenberg form.
impl<T> Matrix<T> where T: Any + Float
fn lup_decomp(&self) -> Result<(Matrix<T>, Matrix<T>, Matrix<T>), Error>
Computes L, U, and P for LUP decomposition.
Returns L,U, and P respectively.
Examples
use rulinalg::matrix::Matrix; let a = Matrix::new(3,3, vec![1.0,2.0,0.0, 0.0,3.0,4.0, 5.0, 1.0, 2.0]); let (l,u,p) = a.lup_decomp().expect("This matrix should decompose!");
Panics
- Matrix is not square.
Failures
- Matrix cannot be LUP decomposed.
impl<T> Matrix<T> where T: Any + Signed + Float
fn eigenvalues(&self) -> Result<Vec<T>, Error>
Eigenvalues of a square matrix.
Returns a Vec of eigenvalues.
Examples
use rulinalg::matrix::Matrix; let a = Matrix::new(4,4, (1..17).map(|v| v as f64).collect::<Vec<f64>>()); let e = a.eigenvalues().expect("We should be able to compute these eigenvalues!"); println!("{:?}", e);
Panics
- The matrix is not square.
Failures
- Eigenvalues cannot be computed.
fn eigendecomp(&self) -> Result<(Vec<T>, Matrix<T>), Error>
Eigendecomposition of a square matrix.
Returns a Vec of eigenvalues, and a matrix with eigenvectors as the columns.
The eigenvectors are only gauranteed to be correct if the matrix is real-symmetric.
Examples
use rulinalg::matrix::Matrix; let a = Matrix::new(3,3,vec![3.,2.,4.,2.,0.,2.,4.,2.,3.]); let (e, m) = a.eigendecomp().expect("We should be able to compute this eigendecomp!"); println!("{:?}", e); println!("{:?}", m.data());
Panics
- The matrix is not square.
Failures
- The eigen decomposition can not be computed.
impl<T> Matrix<T>
fn new<U>(rows: usize, cols: usize, data: U) -> Matrix<T> where U: Into<Vec<T>>
Constructor for Matrix struct.
Requires both the row and column dimensions.
Examples
use rulinalg::matrix::{Matrix, BaseMatrix}; let mat = Matrix::new(2,2, vec![1.0,2.0,3.0,4.0]); assert_eq!(mat.rows(), 2); assert_eq!(mat.cols(), 2);
Panics
- The input data does not match the given dimensions.
fn from_fn<F>(rows: usize, cols: usize, f: F) -> Matrix<T> where F: FnMut(usize, usize) -> T
Constructor for Matrix struct that takes a function f
and constructs a new matrix such that A_ij = f(i, j)
,
where i
is the row index and j
the column index.
Requires both the row and column dimensions as well as a generating function.
Examples
use rulinalg::matrix::{Matrix, BaseMatrix}; // Let's assume you have an array of "things" for // which you want to generate a distance matrix: let things: [i32; 3] = [1, 2, 3]; let distances: Matrix<f64> = Matrix::from_fn(things.len(), things.len(), |col, row| { (things[col] - things[row]).abs().into() }); assert_eq!(distances.rows(), 3); assert_eq!(distances.cols(), 3); assert_eq!(distances.data(), &vec![ 0.0, 1.0, 2.0, 1.0, 0.0, 1.0, 2.0, 1.0, 0.0, ]);
fn data(&self) -> &Vec<T>
Returns a non-mutable reference to the underlying data.
fn mut_data(&mut self) -> &mut [T]
Returns a mutable slice of the underlying data.
fn into_vec(self) -> Vec<T>
Consumes the Matrix and returns the Vec of data.
impl<T> Matrix<T> where T: Clone + Zero
fn zeros(rows: usize, cols: usize) -> Matrix<T>
Constructs matrix of all zeros.
Requires both the row and the column dimensions.
Examples
use rulinalg::matrix::Matrix; let mat = Matrix::<f64>::zeros(2,3);
fn from_diag(diag: &[T]) -> Matrix<T>
Constructs matrix with given diagonal.
Requires slice of diagonal elements.
Examples
use rulinalg::matrix::Matrix; let mat = Matrix::from_diag(&vec![1.0,2.0,3.0,4.0]);
impl<T> Matrix<T> where T: Clone + One
fn ones(rows: usize, cols: usize) -> Matrix<T>
Constructs matrix of all ones.
Requires both the row and the column dimensions.
Examples
use rulinalg::matrix::Matrix; let mat = Matrix::<f64>::ones(2,3);
impl<T> Matrix<T> where T: Clone + Zero + One
fn identity(size: usize) -> Matrix<T>
Constructs the identity matrix.
Requires the size of the matrix.
Examples
use rulinalg::matrix::Matrix; let I = Matrix::<f64>::identity(4);
impl<T> Matrix<T> where T: Float + FromPrimitive
fn mean(&self, axis: Axes) -> Vector<T>
The mean of the matrix along the specified axis.
- Axis Row - Arithmetic mean of rows.
- Axis Col - Arithmetic mean of columns.
Calling mean()
on an empty matrix will return an empty matrix.
Examples
use rulinalg::matrix::{Matrix, Axes}; let a = Matrix::<f64>::new(2,2, vec![1.0,2.0,3.0,4.0]); let c = a.mean(Axes::Row); assert_eq!(*c.data(), vec![2.0, 3.0]); let d = a.mean(Axes::Col); assert_eq!(*d.data(), vec![1.5, 3.5]);
fn variance(&self, axis: Axes) -> Result<Vector<T>, Error>
The variance of the matrix along the specified axis.
- Axis Row - Sample variance of rows.
- Axis Col - Sample variance of columns.
Examples
use rulinalg::matrix::{Matrix, Axes}; let a = Matrix::<f32>::new(2,2,vec![1.0,2.0,3.0,4.0]); let c = a.variance(Axes::Row).unwrap(); assert_eq!(*c.data(), vec![2.0, 2.0]); let d = a.variance(Axes::Col).unwrap(); assert_eq!(*d.data(), vec![0.5, 0.5]);
Failures
- There are one or fewer row/columns in the working axis.
impl<T> Matrix<T> where T: Any + Float
fn solve(&self, y: Vector<T>) -> Result<Vector<T>, Error>
Solves the equation Ax = y
.
Requires a Vector y
as input.
Examples
use rulinalg::matrix::Matrix; use rulinalg::vector::Vector; let a = Matrix::new(2,2, vec![2.0,3.0,1.0,2.0]); let y = Vector::new(vec![13.0,8.0]); let x = a.solve(y).unwrap(); assert_eq!(*x.data(), vec![2.0, 3.0]);
Panics
- The matrix column count and vector size are different.
- The matrix is not square.
Failures
- The matrix cannot be decomposed into an LUP form to solve.
- There is no valid solution as the matrix is singular.
fn inverse(&self) -> Result<Matrix<T>, Error>
Computes the inverse of the matrix.
Examples
use rulinalg::matrix::Matrix; let a = Matrix::new(2,2, vec![2.,3.,1.,2.]); let inv = a.inverse().expect("This matrix should have an inverse!"); let I = a * inv; assert_eq!(*I.data(), vec![1.0,0.0,0.0,1.0]);
Panics
- The matrix is not square.
Failures
- The matrix could not be LUP decomposed.
- The matrix has zero determinant.
fn det(&self) -> T
Trait Implementations
impl<T> Metric<T> for Matrix<T> where T: Float
fn norm(&self) -> T
Compute euclidean norm for matrix.
Examples
use rulinalg::matrix::Matrix; use rulinalg::Metric; let a = Matrix::new(2,1, vec![3.0,4.0]); let c = a.norm(); assert_eq!(c, 5.0);
impl<T> Eq for Matrix<T> where T: Eq
impl<'a, T> FromIterator<&'a [T]> for Matrix<T> where T: Copy + 'a
Creates a Matrix
from an iterator over slices.
Each of the slices produced by the iterator will become a row in the matrix.
Panics
Will panic if the iterators items do not have constant length.
Examples
We can create a new matrix from some data.
use rulinalg::matrix::{Matrix, BaseMatrix}; let a : Matrix<f64> = vec![4f64; 16].chunks(4).collect(); assert_eq!(a.rows(), 4); assert_eq!(a.cols(), 4);
We can also do more interesting things.
use rulinalg::matrix::{Matrix, BaseMatrix}; let a = Matrix::new(4,2, (0..8).collect::<Vec<usize>>()); // Here we skip the first row and take only those // where the first entry is less than 6. let b = a.iter_rows() .skip(1) .filter(|x| x[0] < 6) .collect::<Matrix<usize>>(); // We take the middle rows assert_eq!(b.into_vec(), vec![2,3,4,5]);
fn from_iter<I>(iterable: I) -> Matrix<T> where I: IntoIterator<Item=&'a [T]>
impl<T> BaseMatrix<T> for Matrix<T>
fn rows(&self) -> usize
Rows in the matrix.
fn cols(&self) -> usize
Columns in the matrix.
fn row_stride(&self) -> usize
Row stride in the matrix.
fn is_empty(&self) -> bool
Returns true if the matrix contais no elements
fn as_ptr(&self) -> *const T
Top left index of the matrix.
fn into_matrix(self) -> Matrix<T> where T: Copy
Convert the matrix struct into a owned Matrix.
fn sum(&self) -> T where T: Copy + Zero<Output=T> + Add<T>
The sum of all elements in the matrix Read more
fn elemul(&self, m: &Matrix<T>) -> Matrix<T> where T: Copy + Mul<T, Output=T>
The elementwise product of two matrices. Read more
fn elediv(&self, m: &Matrix<T>) -> Matrix<T> where T: Copy + Div<T, Output=T>
The elementwise division of two matrices. Read more
fn vcat<S>(&self, m: &S) -> Matrix<T> where S: BaseMatrix<T>, T: Copy
Vertically concatenates two matrices. With self on top. Read more
fn as_slice(&self) -> MatrixSlice<T>
Returns a MatrixSlice
over the whole matrix. Read more
unsafe fn get_unchecked(&self, index: [usize; 2]) -> &T
Get a reference to a point in the matrix without bounds checking.
fn get_row(&self, index: usize) -> Option<&[T]>
Returns the row of a matrix at the given index. None
if the index is out of bounds. Read more
unsafe fn get_row_unchecked(&self, index: usize) -> &[T]
Returns the row of a matrix at the given index without doing unbounds checking Read more
fn iter<'a>(&self) -> SliceIter<'a, T> where T: 'a
Returns an iterator over the matrix data. Read more
fn iter_rows(&self) -> Rows<T>
Iterate over the rows of the matrix. Read more
fn iter_diag(&self, k: DiagOffset) -> Diagonal<T, Self>
Iterate over diagonal entries Read more
fn sum_rows(&self) -> Vector<T> where T: Copy + Zero<Output=T> + Add<T>
The sum of the rows of the matrix. Read more
fn sum_cols(&self) -> Vector<T> where T: Copy + Zero<Output=T> + Add<T>
The sum of the columns of the matrix. Read more
fn select_rows<'a, I>(&self, rows: I) -> Matrix<T> where I: IntoIterator<Item=&'a usize>, T: Copy, I::IntoIter: ExactSizeIterator, I::IntoIter: Clone
Select rows from matrix Read more
fn select_cols<'a, I>(&self, cols: I) -> Matrix<T> where I: IntoIterator<Item=&'a usize>, T: Copy, I::IntoIter: ExactSizeIterator, I::IntoIter: Clone
Select columns from matrix Read more
fn select(&self, rows: &[usize], cols: &[usize]) -> Matrix<T> where T: Copy
Select block matrix from matrix Read more
fn hcat<S>(&self, m: &S) -> Matrix<T> where S: BaseMatrix<T>, T: Copy
Horizontally concatenates two matrices. With self on the left. Read more
fn diag(&self) -> Vector<T> where T: Copy
Extract the diagonal of the matrix Read more
fn transpose(&self) -> Matrix<T> where T: Copy
Tranposes the given matrix Read more
fn is_diag(&self) -> bool where T: Zero + PartialEq<T>
Checks if matrix is diagonal. Read more
fn solve_u_triangular(&self, y: Vector<T>) -> Result<Vector<T>, Error> where T: Any + Float
Solves an upper triangular linear system. Read more
fn solve_l_triangular(&self, y: Vector<T>) -> Result<Vector<T>, Error> where T: Any + Float
Solves a lower triangular linear system. Read more
fn split_at(&self, mid: usize, axis: Axes) -> (MatrixSlice<T>, MatrixSlice<T>)
Split the matrix at the specified axis returning two MatrixSlice
s. Read more
fn sub_slice<'a>(&self,
start: [usize; 2],
rows: usize,
cols: usize)
-> MatrixSlice<'a, T> where T: 'a
start: [usize; 2],
rows: usize,
cols: usize)
-> MatrixSlice<'a, T> where T: 'a
Produce a MatrixSlice
from an existing matrix. Read more
impl<T> AddAssign<T> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs addition assignment between a matrix and a scalar.
fn add_assign(&mut self, _rhs: T)
impl<'a, T> AddAssign<&'a T> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs addition assignment between a matrix and a scalar.
fn add_assign(&mut self, _rhs: &T)
impl<T> AddAssign<Matrix<T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition assignment between two matrices.
fn add_assign(&mut self, _rhs: Matrix<T>)
impl<'a, T> AddAssign<&'a Matrix<T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition assignment between two matrices.
fn add_assign(&mut self, _rhs: &Matrix<T>)
impl<'a, T> AddAssign<MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition assignment between two matrices.
fn add_assign(&mut self, _rhs: MatrixSlice<T>)
impl<'a, 'b, T> AddAssign<&'b MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition assignment between two matrices.
fn add_assign(&mut self, _rhs: &MatrixSlice<T>)
impl<'a, T> AddAssign<MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition assignment between two matrices.
fn add_assign(&mut self, _rhs: MatrixSliceMut<T>)
impl<'a, 'b, T> AddAssign<&'b MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition assignment between two matrices.
fn add_assign(&mut self, _rhs: &MatrixSliceMut<T>)
impl<T> DivAssign<T> for Matrix<T> where T: Copy + Div<T, Output=T>
Performs division assignment between a matrix and a scalar.
fn div_assign(&mut self, _rhs: T)
impl<'a, T> DivAssign<&'a T> for Matrix<T> where T: Copy + Div<T, Output=T>
Performs division assignment between a matrix and a scalar.
fn div_assign(&mut self, _rhs: &T)
impl<T> MulAssign<T> for Matrix<T> where T: Copy + Mul<T, Output=T>
Performs multiplication assignment between a matrix and a scalar.
fn mul_assign(&mut self, _rhs: T)
impl<'a, T> MulAssign<&'a T> for Matrix<T> where T: Copy + Mul<T, Output=T>
Performs multiplication assignment between a matrix and a scalar.
fn mul_assign(&mut self, _rhs: &T)
impl<T> Sub<T> for Matrix<T> where T: Copy + Sub<T, Output=T>
Scalar subtraction with matrix.
Will reuse the memory allocated for the existing matrix.
impl<'a, T> Sub<&'a T> for Matrix<T> where T: Copy + Sub<T, Output=T>
Scalar subtraction with matrix.
Will reuse the memory allocated for the existing matrix.
impl<'a, T> Sub<T> for &'a Matrix<T> where T: Copy + Sub<T, Output=T>
Scalar subtraction with matrix.
impl<'a, 'b, T> Sub<&'b T> for &'a Matrix<T> where T: Copy + Sub<T, Output=T>
Scalar subtraction with matrix.
impl<'a, T> Sub<MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise
subtraction
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
fn sub(self, s: MatrixSlice<T>) -> Matrix<T>
impl<'a, 'b, T> Sub<MatrixSlice<'a, T>> for &'b Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise
subtraction
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
fn sub(self, s: MatrixSlice<T>) -> Matrix<T>
impl<'a, 'b, T> Sub<&'b MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise
subtraction
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
fn sub(self, s: &MatrixSlice<T>) -> Matrix<T>
impl<'a, 'b, 'c, T> Sub<&'c MatrixSlice<'a, T>> for &'b Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise
subtraction
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
fn sub(self, s: &MatrixSlice<T>) -> Matrix<T>
impl<'a, T> Sub<MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise
subtraction
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
fn sub(self, s: MatrixSliceMut<T>) -> Matrix<T>
impl<'a, 'b, T> Sub<MatrixSliceMut<'a, T>> for &'b Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise
subtraction
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
fn sub(self, s: MatrixSliceMut<T>) -> Matrix<T>
impl<'a, 'b, T> Sub<&'b MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise
subtraction
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
fn sub(self, s: &MatrixSliceMut<T>) -> Matrix<T>
impl<'a, 'b, 'c, T> Sub<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise
subtraction
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
fn sub(self, s: &MatrixSliceMut<T>) -> Matrix<T>
impl<T> Sub<Matrix<T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction between two matrices.
This will reuse allocated memory from self
.
impl<'a, T> Sub<Matrix<T>> for &'a Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction between two matrices.
This will reuse allocated memory from m
.
impl<'a, T> Sub<&'a Matrix<T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction between two matrices.
This will reuse allocated memory from self
.
impl<'a, 'b, T> Sub<&'b Matrix<T>> for &'a Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction between two matrices.
impl<T> Clone for Matrix<T> where T: Clone
fn clone(&self) -> Matrix<T>
Clones the Matrix.
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T> Hash for Matrix<T> where T: Hash
fn hash<__HT>(&self, __arg_0: &mut __HT) where __HT: Hasher
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl<T> Mul<Vector<T>> for Matrix<T> where T: Zero<Output=T> + Mul<T, Output=T> + Add<T> + Copy
Multiplies matrix by vector.
type Output = Vector<T>
The resulting type after applying the *
operator
fn mul(self, m: Vector<T>) -> Vector<T>
The method for the *
operator
impl<'a, T> Mul<Vector<T>> for &'a Matrix<T> where T: Zero<Output=T> + Mul<T, Output=T> + Add<T> + Copy
Multiplies matrix by vector.
type Output = Vector<T>
The resulting type after applying the *
operator
fn mul(self, m: Vector<T>) -> Vector<T>
The method for the *
operator
impl<'a, T> Mul<&'a Vector<T>> for Matrix<T> where T: Zero<Output=T> + Mul<T, Output=T> + Add<T> + Copy
Multiplies matrix by vector.
type Output = Vector<T>
The resulting type after applying the *
operator
fn mul(self, m: &Vector<T>) -> Vector<T>
The method for the *
operator
impl<'a, 'b, T> Mul<&'b Vector<T>> for &'a Matrix<T> where T: Zero<Output=T> + Mul<T, Output=T> + Add<T> + Copy
Multiplies matrix by vector.
type Output = Vector<T>
The resulting type after applying the *
operator
fn mul(self, v: &Vector<T>) -> Vector<T>
The method for the *
operator
impl<'a, T> Mul<Matrix<T>> for Matrix<T> where T: Add<T, Output=T> + Mul<T, Output=T> + Any + Zero + Copy
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: Matrix<T>) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, T> Mul<&'a Matrix<T>> for Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: &Matrix<T>) -> Matrix<T>
The method for the *
operator
impl<'a, T> Mul<Matrix<T>> for &'a Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: Matrix<T>) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, T> Mul<&'b Matrix<T>> for &'a Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: &Matrix<T>) -> Matrix<T>
The method for the *
operator
impl<T> Mul<T> for Matrix<T> where T: Copy + Mul<T, Output=T>
Scalar multiplication with matrix.
Will reuse the memory allocated for the existing matrix.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, f: T) -> Matrix<T>
The method for the *
operator
impl<'a, T> Mul<&'a T> for Matrix<T> where T: Copy + Mul<T, Output=T>
Scalar multiplication with matrix.
Will reuse the memory allocated for the existing matrix.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, f: &T) -> Matrix<T>
The method for the *
operator
impl<'a, T> Mul<T> for &'a Matrix<T> where T: Copy + Mul<T, Output=T>
Scalar multiplication with matrix.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, f: T) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, T> Mul<&'b T> for &'a Matrix<T> where T: Copy + Mul<T, Output=T>
Scalar multiplication with matrix.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, f: &T) -> Matrix<T>
The method for the *
operator
impl<'a, T> Mul<MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: MatrixSlice<T>) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, T> Mul<&'b MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: &MatrixSlice<T>) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, T> Mul<MatrixSlice<'a, T>> for &'b Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: MatrixSlice<T>) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, 'c, T> Mul<&'c MatrixSlice<'a, T>> for &'b Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: &MatrixSlice<T>) -> Matrix<T>
The method for the *
operator
impl<'a, T> Mul<MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: MatrixSliceMut<T>) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, T> Mul<&'b MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: &MatrixSliceMut<T>) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, T> Mul<MatrixSliceMut<'a, T>> for &'b Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: MatrixSliceMut<T>) -> Matrix<T>
The method for the *
operator
impl<'a, 'b, 'c, T> Mul<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T> where T: Copy + Zero<Output=T> + Add<T> + Mul<T, Output=T> + Any
Multiplies two matrices together.
type Output = Matrix<T>
The resulting type after applying the *
operator
fn mul(self, m: &MatrixSliceMut<T>) -> Matrix<T>
The method for the *
operator
impl<T> BaseMatrixMut<T> for Matrix<T>
fn as_mut_ptr(&mut self) -> *mut T
Top left index of the slice.
fn as_mut_slice(&mut self) -> MatrixSliceMut<T>
Returns a MatrixSliceMut
over the whole matrix. Read more
unsafe fn get_unchecked_mut(&mut self, index: [usize; 2]) -> &mut T
Get a mutable reference to a point in the matrix without bounds checks.
fn iter_mut<'a>(&mut self) -> SliceIterMut<'a, T> where T: 'a
Returns a mutable iterator over the matrix. Read more
fn get_row_mut(&mut self, index: usize) -> Option<&mut [T]>
Returns a mutable reference to the row of a matrix at the given index. None
if the index is out of bounds. Read more
unsafe fn get_row_unchecked_mut(&mut self, index: usize) -> &mut [T]
Returns a mutable reference to the row of a matrix at the given index without doing unbounds checking Read more
fn swap_rows(&mut self, a: usize, b: usize)
Swaps two rows in a matrix. Read more
fn swap_cols(&mut self, a: usize, b: usize)
Swaps two columns in a matrix. Read more
fn iter_rows_mut(&mut self) -> RowsMut<T>
Iterate over the mutable rows of the matrix. Read more
fn iter_diag_mut(&mut self, k: DiagOffset) -> DiagonalMut<T, Self>
Iterate over diagonal entries mutably Read more
fn set_to<M>(self, target: M) where M: BaseMatrix<T>, T: Copy
Sets the underlying matrix data to the target data. Read more
fn apply(self, f: &Fn(T)) -> Self where T: Copy
Applies a function to each element in the matrix. Read more
fn split_at_mut(&mut self,
mid: usize,
axis: Axes)
-> (MatrixSliceMut<T>, MatrixSliceMut<T>)
mid: usize,
axis: Axes)
-> (MatrixSliceMut<T>, MatrixSliceMut<T>)
Split the matrix at the specified axis returning two MatrixSliceMut
s. Read more
fn sub_slice_mut<'a>(&mut self,
start: [usize; 2],
rows: usize,
cols: usize)
-> MatrixSliceMut<'a, T> where T: 'a
start: [usize; 2],
rows: usize,
cols: usize)
-> MatrixSliceMut<'a, T> where T: 'a
Produce a MatrixSliceMut
from an existing matrix. Read more
impl<T> Index<[usize; 2]> for Matrix<T>
Indexes matrix.
Takes row index first then column.
impl<T> Add<T> for Matrix<T> where T: Copy + Add<T, Output=T>
Scalar addition with matrix.
Will reuse the memory allocated for the existing matrix.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, f: T) -> Matrix<T>
The method for the +
operator
impl<'a, T> Add<&'a T> for Matrix<T> where T: Copy + Add<T, Output=T>
Scalar addition with matrix.
Will reuse the memory allocated for the existing matrix.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, f: &T) -> Matrix<T>
The method for the +
operator
impl<'a, T> Add<T> for &'a Matrix<T> where T: Copy + Add<T, Output=T>
Scalar addition with matrix.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, f: T) -> Matrix<T>
The method for the +
operator
impl<'a, 'b, T> Add<&'b T> for &'a Matrix<T> where T: Copy + Add<T, Output=T>
Scalar addition with matrix.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, f: &T) -> Matrix<T>
The method for the +
operator
impl<'a, T> Add<MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise
addition
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, s: MatrixSlice<T>) -> Matrix<T>
The method for the +
operator
impl<'a, 'b, T> Add<MatrixSlice<'a, T>> for &'b Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise
addition
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, s: MatrixSlice<T>) -> Matrix<T>
The method for the +
operator
impl<'a, 'b, T> Add<&'b MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise
addition
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, s: &MatrixSlice<T>) -> Matrix<T>
The method for the +
operator
impl<'a, 'b, 'c, T> Add<&'c MatrixSlice<'a, T>> for &'b Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise
addition
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, s: &MatrixSlice<T>) -> Matrix<T>
The method for the +
operator
impl<'a, T> Add<MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise
addition
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, s: MatrixSliceMut<T>) -> Matrix<T>
The method for the +
operator
impl<'a, 'b, T> Add<MatrixSliceMut<'a, T>> for &'b Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise
addition
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, s: MatrixSliceMut<T>) -> Matrix<T>
The method for the +
operator
impl<'a, 'b, T> Add<&'b MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise
addition
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, s: &MatrixSliceMut<T>) -> Matrix<T>
The method for the +
operator
impl<'a, 'b, 'c, T> Add<&'c MatrixSliceMut<'a, T>> for &'b Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise
addition
between Matrix
and MatrixSlice
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, s: &MatrixSliceMut<T>) -> Matrix<T>
The method for the +
operator
impl<T> Add<Matrix<T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition between two matrices.
This will reuse allocated memory from self
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, m: Matrix<T>) -> Matrix<T>
The method for the +
operator
impl<'a, T> Add<Matrix<T>> for &'a Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition between two matrices.
This will reuse allocated memory from m
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, m: Matrix<T>) -> Matrix<T>
The method for the +
operator
impl<'a, T> Add<&'a Matrix<T>> for Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition between two matrices.
This will reuse allocated memory from self
.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, m: &Matrix<T>) -> Matrix<T>
The method for the +
operator
impl<'a, 'b, T> Add<&'b Matrix<T>> for &'a Matrix<T> where T: Copy + Add<T, Output=T>
Performs elementwise addition between two matrices.
type Output = Matrix<T>
The resulting type after applying the +
operator
fn add(self, m: &Matrix<T>) -> Matrix<T>
The method for the +
operator
impl<T> PartialEq<Matrix<T>> for Matrix<T> where T: PartialEq<T>
fn eq(&self, __arg_0: &Matrix<T>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Matrix<T>) -> bool
This method tests for !=
.
impl<T> IndexMut<[usize; 2]> for Matrix<T>
Indexes mutable matrix.
Takes row index first then column.
impl<T> Debug for Matrix<T> where T: Debug
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl<T> SubAssign<T> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs subtraction assignment between a matrix and a scalar.
fn sub_assign(&mut self, _rhs: T)
impl<'a, T> SubAssign<&'a T> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs subtraction assignment between a matrix and a scalar.
fn sub_assign(&mut self, _rhs: &T)
impl<T> SubAssign<Matrix<T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction assignment between two matrices.
fn sub_assign(&mut self, _rhs: Matrix<T>)
impl<'a, T> SubAssign<&'a Matrix<T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction assignment between two matrices.
fn sub_assign(&mut self, _rhs: &Matrix<T>)
impl<'a, T> SubAssign<MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction assignment between two matrices.
fn sub_assign(&mut self, _rhs: MatrixSlice<T>)
impl<'a, 'b, T> SubAssign<&'b MatrixSlice<'a, T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction assignment between two matrices.
fn sub_assign(&mut self, _rhs: &MatrixSlice<T>)
impl<'a, T> SubAssign<MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction assignment between two matrices.
fn sub_assign(&mut self, _rhs: MatrixSliceMut<T>)
impl<'a, 'b, T> SubAssign<&'b MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy + Sub<T, Output=T>
Performs elementwise subtraction assignment between two matrices.
fn sub_assign(&mut self, _rhs: &MatrixSliceMut<T>)
impl<T> Display for Matrix<T> where T: Display
impl<T> From<Vector<T>> for Matrix<T>
impl<'a, T> From<MatrixSlice<'a, T>> for Matrix<T> where T: Copy
fn from(slice: MatrixSlice<'a, T>) -> Matrix<T>
Performs the conversion.
impl<'a, T> From<MatrixSliceMut<'a, T>> for Matrix<T> where T: Copy
fn from(slice: MatrixSliceMut<'a, T>) -> Matrix<T>
Performs the conversion.
impl<T> Div<T> for Matrix<T> where T: Copy + Div<T, Output=T>
Scalar division with matrix.
Will reuse the memory allocated for the existing matrix.
impl<'a, T> Div<&'a T> for Matrix<T> where T: Copy + Div<T, Output=T>
Scalar division with matrix.
Will reuse the memory allocated for the existing matrix.
impl<'a, T> Div<T> for &'a Matrix<T> where T: Copy + Div<T, Output=T>
Scalar division with matrix.
impl<'a, 'b, T> Div<&'b T> for &'a Matrix<T> where T: Copy + Div<T, Output=T>
Scalar division with matrix.
impl<T> Neg for Matrix<T> where T: Neg<Output=T> + Copy
Gets negative of matrix.
impl<'a, T> Neg for &'a Matrix<T> where T: Neg<Output=T> + Copy
Gets negative of matrix.