Struct matrix::matrix::Matrix

source ·
pub struct Matrix<K: Scalar> {
    pub data: Vec<Vec<K>>,
}
Expand description

A struct representing a mathematical matrix.

The Matrix struct is generic over type K that implements the Scalar type, that which ensures that it supports basic arithmetic operations like addition, subtraction, multiplication, and division.

Fields§

§data: Vec<Vec<K>>

Implementations§

source§

impl<K: Scalar> Matrix<K>

source

pub fn new(data: Vec<Vec<K>>) -> Self

Creates a new Matrix<K> from a matrix of matrices (rows of the matrix).

§Arguments
  • data - A 2D matrix of K values representing the rows of the matrix.
§Example
use matrix::Matrix;

let mat = Matrix::new(vec![vec![1.0, 2.0], vec![3.0, 4.0]]);
source

pub fn size(&self) -> (usize, usize)

Returns the size (i.e., number of rows and columns) of the matrix.

§Returns

A tuple (rows, cols) representing the dimensions of the matrix.

§Example
use matrix::Matrix;

let mat = Matrix::new(vec![vec![1.0, 2.0], vec![3.0, 4.0]]);
assert_eq!(mat.size(), (2, 2));
source

pub fn rows(&self) -> usize

Returns the number of rows in the matrix.

This function provides the total count of rows in the matrix data structure. Each row in the matrix corresponds to a nested vector within self.data, so the number of rows is determined by the length of self.data.

§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![1, 2, 3],
    vec![4, 5, 6]
]);

assert_eq!(mat.rows(), 2);
§Returns

The number of rows in the matrix as usize.

source

pub fn cols(&self) -> usize

Returns the number of columns in the matrix.

This function provides the count of columns in the matrix data structure. Each row in the matrix has the same number of elements, representing columns, so the number of columns is derived from the length of any row within self.data.

§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![1, 2, 3],
    vec![4, 5, 6]
]);

assert_eq!(mat.cols(), 3);
§Returns

The number of columns in the matrix as usize.

§Panics

This function will panic if the matrix contains no rows.

source

pub fn is_square(&self) -> bool

Returns whether the matrix is square.

A matrix is square if the number of rows equals the number of columns.

§Example
use matrix::Matrix;

let mat = Matrix::new(vec![vec![1.0, 2.0], vec![3.0, 4.0]]);
assert!(mat.is_square());
source

pub fn print(&self)

Prints the contents of the matrix to the standard output.

The matrix will be printed row by row, with each row on a new line, like:

[1.0, 2.0]
[3.0, 4.0]
§Example
use matrix::Matrix;

let mat = Matrix::new(vec![vec![1.0, 2.0], vec![3.0, 4.0]]);
mat.print();
source

pub fn flatten(&self) -> Vector<K>

Reshapes the Martix into a Vector by flattening its rows.

§Example
use matrix::Matrix;

let mat = Matrix::new(vec![vec![1.0, 2.0], vec![3.0, 4.0]]);
let vec = mat.flatten();
assert_eq!(vec.size(), 4);
source

pub fn add(&mut self, v: &Matrix<K>)

Adds another Matrix<K> to the calling Matrix<K>.

§Arguments
  • v - A reference to the other Matrix<K> to add.
§Panics

This function will panic if the matrixes are not of the same size.

§Example
use matrix::Matrix;

let mut mat1 = Matrix::new(vec![
    vec![42.0, 4.2],
    vec![1.0, 2.0]
]);
let mat2 = Matrix::new(vec![
    vec![-42.0, 4.2],
    vec![1.0, 2.0]
]);

mat1.add(&mat2);

assert_eq!(mat1.data, vec![
    vec![0.0, 8.4],
    vec![2.0, 4.0]
]);
source

pub fn sub(&mut self, v: &Matrix<K>)

Substracts another Matrix<K> to the calling Matrix<K>.

§Arguments
  • v - A reference to the other Matrix<K> to subtract.
§Panics

This function will panic if the Matrixs are not of the same size.

§Example
use matrix::Matrix;

let mut mat1 = Matrix::new(vec![
    vec![42.0, 4.2],
    vec![1.0, 2.0]
]);
let mat2 = Matrix::new(vec![
    vec![1.0, 2.0],
    vec![-42.0, 4.2]
]);

mat1.sub(&mat2);

assert_eq!(mat1.data, vec![
    vec![42.0 - 1.0, 4.2 - 2.0],
    vec![1.0 - -42.0, 2.0 - 4.2]
]);
source

pub fn scl(&mut self, a: K)

Scales the calling Matrix<K> by a factor a.

Each element in the Matrix is multiplied by the scalar a.

§Arguments
  • a - The scaling factor.
§Example
use matrix::Matrix;

let mut mat = Matrix::new(vec![
    vec![1.0, 2.0],
    vec![3.0, 4.0]
]);

mat.scl(2.0); // Scale by 2

assert_eq!(mat.data, vec![
    vec![2.0, 4.0],
    vec![6.0, 8.0]
]);
source

pub fn mul_vec(&self, vec: &Vector<K>) -> Vector<K>

Multiplies the matrix self by a vector vec, producing a new vector as the result.

This function performs a matrix-vector multiplication, where self is an (m x n) matrix and vec is a vector of size (n). The resulting vector will have a size of (m).

Given a matrix (A) and a vector (u), the product (v = A x u) is calculated as follows:

v[i] = sum(A[i][j] * u[j] for j in 0..n)

where:

  • i iterates over the rows of the matrix A (from 0 to m-1),
  • j iterates over the columns of A and the elements of the vector u (from 0 to n-1).

Each element v[i] in the resulting vector is the dot product of the i-th row of A with the vector u.

§Arguments
  • vec - A Vector<K> representing the vector to multiply with the matrix.
§Panics

This function will panic if the number of columns in the matrix does not match the vector’s size, as the multiplication would be undefined in that case.

§Returns

A Vector<K> that is the result of the matrix-vector multiplication, with a length equal to the number of rows in self.

§Example
use matrix::{Matrix, Vector};

// Define a 2x3 matrix
let mat = Matrix::new(vec![
    vec![1.0, 2.0, 3.0],
    vec![4.0, 5.0, 6.0],
]);

// Define a vector of size 3
let vec = Vector::new(vec![7.0, 8.0, 9.0]);

// Multiply the matrix by the vector
let result = mat.mul_vec(&vec);

// Expected result is a vector of size 2:
// [50.0, 122.0]
assert_eq!(result.data, vec![50.0, 122.0]);
source

pub fn mul_mat(&self, other: &Matrix<K>) -> Matrix<K>

Multiplies self with another matrix other.

This function performs matrix multiplication on two matrices, self and other, and returns a new matrix. The resulting matrix will have dimensions m x p, where:

  • m is the number of rows in self.
  • p is the number of columns in other.

Given two matrices, A and B, the product C = A * B is calculated as follows:

C[i][j] = sum(A[i][k] * B[k][j] for k in 0..n)

where:

  • i is the row index of A (from 0 to m-1)
  • j is the column index of B (from 0 to p-1)
  • k iterates over the shared dimension (from 0 to n-1).

Each element C[i][j] in the resulting matrix is the dot product of the i-th row of A and the j-th column of B.

§Arguments
  • other - A reference to another Matrix<K> to multiply with self.
§Panics

This function will panic if the number of columns in self does not match the number of rows in other, as this makes matrix multiplication undefined.

§Returns

A new Matrix<K> containing the product of self and other, with dimensions m x p.

§Example
use matrix::Matrix;

// Define a 2x3 matrix
let mat1 = Matrix::new(vec![
    vec![1.0, 2.0, 3.0],
    vec![4.0, 5.0, 6.0],
]);

// Define a 3x2 matrix
let mat2 = Matrix::new(vec![
    vec![7.0, 8.0],
    vec![9.0, 10.0],
    vec![11.0, 12.0],
]);

// Multiply the matrices
let result = mat1.mul_mat(&mat2);

// Expected result is a 2x2 matrix:
// [[58.0, 64.0],
//  [139.0, 154.0]]
assert_eq!(result.data, vec![
    vec![58.0, 64.0],
    vec![139.0, 154.0],
]);
source

pub fn trace(&self) -> K

Computes the trace of a square matrix, which is the sum of its diagonal elements.

For a square matrix A of size n x n, the trace is defined as the sum of all elements along the diagonal, where each diagonal element is represented as A[i][i].

For a matrix A:

trace(A) = A[0][0] + A[1][1] + ... + A[n-1][n-1]
  • Time Complexity: O(n), where n is the number of rows (or columns) in the matrix. The function iterates only through the diagonal elements.
  • Space Complexity: O(1), since only a single accumulator variable is used.
§Returns

Returns a value of type K, representing the trace of the matrix.

§Panics

This function will panic if the matrix is not square, i.e., if the number of rows does not equal the number of columns. The trace is only defined for square matrices.

§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![1.0_f32, 2.0, 3.0],
    vec![4.0, 5.0, 6.0],
    vec![7.0, 8.0, 9.0],
]);
assert_eq!(mat.trace(), 15.0); // 1.0 + 5.0 + 9.0
source

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

Returns the transpose of the matrix.

Given a matrix A with dimensions m x n, this function produces a matrix B with dimensions n x m, where each element B[j][i] is equal to A[i][j].

§Formula

For a matrix A:

B[j][i] = A[i][j]
§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![1.0, 2.0, 3.0],
    vec![4.0, 5.0, 6.0]
]);
let transposed = mat.transpose();

assert_eq!(transposed, Matrix::new(vec![
    vec![1.0, 4.0],
    vec![2.0, 5.0],
    vec![3.0, 6.0],
]));
§Returns

A new Matrix<K> which is the transpose of the original matrix.

source

pub fn row_echelon(&self) -> Matrix<K>

Converts the matrix to its reduced row-echelon form (RREF) using Gauss-Jordan elimination.

§Panics

This function will panic if the matrix is empty or not rectangular.

§Example
use matrix::Matrix;

let mut mat = Matrix::new(vec![
    vec![2.0, 1.0, -1.0],
    vec![-3.0, -1.0, 2.0],
    vec![-2.0, 1.0, 2.0],
]);
let rref = mat.row_echelon();
§Returns

A new matrix in reduced row-echelon form.

source

fn minor(&self, row: usize, col: usize) -> Matrix<K>

Returns the minor matrix by removing the specified row and column.

Given a square matrix, this function returns a new matrix that is one size smaller, with the specified row and column removed.

§Parameters
  • row: The row index to remove.
  • col: The column index to remove.
§Panics
  • Panics if the matrix is not square.
  • Panics if the matrix is 0x0 or if row or col are out of bounds.
§Returns

A new Matrix<K> that is the minor matrix of the original matrix.

source

fn determinant2x2(&self) -> K

Computes the determinant of a 2x2 matrix.

Given a 2x2 matrix A, the determinant is calculated as:

det(A) = A[0][0] * A[1][1] - A[0][1] * A[1][0]
§Returns

A value of type K representing the determinant of the matrix.

§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![3.0, 8.0],
    vec![4.0, 6.0]
]);
assert_eq!(mat.determinant(), -14.0);
source

fn determinant3x3(&self) -> K

Computes the determinant of a 3x3 matrix using cofactor expansion along the first row.

This function calculates the determinant of a 3x3 matrix by expanding along the first row and using the generic minor function to obtain 2x2 submatrices (minors) dynamically. This approach makes the code more consistent with larger determinant calculations (e.g., for 4x4 matrices), and allows for easier extension to support matrices of other sizes.

§Formula

Given a 3x3 matrix A:

A = | A_11 A_12 A_13 |
    | A_21 A_22 A_23 |
    | A_31 A_32 A_33 |

the determinant is calculated as:

det(A) = A_11 * det(M_11) - A_12 * det(M_12) + A_13 * det(M_13)

where:

  • M_11 is the minor obtained by removing the first row and first column of A,
  • M_12 is the minor obtained by removing the first row and second column of A,
  • M_13 is the minor obtained by removing the first row and third column of A, and det(M_ij) represents the determinant of each 2x2 minor.
§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![3.0, 8.0, 4.0],
    vec![2.0, 1.0, 7.0],
    vec![6.0, 5.0, 9.0]
]);
let determinant = mat.determinant();

assert_eq!(determinant, 130.0);
§Panics

This function will panic if the matrix is not 3x3. Ensure that the matrix size is 3x3 before calling this function.

§Returns

Returns the determinant of the 3x3 matrix as a scalar value of type K.

source

fn determinant4x4(&self) -> K

Computes the determinant of a 4x4 matrix using cofactor expansion along the first row.

This function calculates the determinant of a 4x4 matrix by expanding along the first row and using the generic minor function to obtain 3x3 submatrices (minors) dynamically. This approach leverages the cofactor expansion, which recursively calls the determinant3x3 method on each minor.

§Formula

Given a 4x4 matrix A:

A = | A_11 A_12 A_13 A_14 |
    | A_21 A_22 A_23 A_24 |
    | A_31 A_32 A_33 A_34 |
    | A_41 A_42 A_43 A_44 |

the determinant is calculated as:

det(A) = A_11 * det(M_11) - A_12 * det(M_12) + A_13 * det(M_13) - A_14 * det(M_14)

where:

  • M_11 is the minor obtained by removing the first row and first column of A,
  • M_12 is the minor obtained by removing the first row and second column of A,
  • M_13 is the minor obtained by removing the first row and third column of A,
  • M_14 is the minor obtained by removing the first row and fourth column of A, and det(M_ij) represents the determinant of each 3x3 minor.
§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![1.0, 2.0, 3.0, 4.0],
    vec![5.0, 6.0, 7.0, 8.0],
    vec![9.0, 10.0, 11.0, 12.0],
    vec![13.0, 14.0, 15.0, 16.0]
]);
let determinant = mat.determinant();

assert_eq!(determinant, 0.0); // Example result; in this case, the matrix is singular
§Panics

This function will panic if the matrix is not 4x4. Ensure that the matrix size is 4x4 before calling this function.

§Returns

Returns the determinant of the 4x4 matrix as a scalar value of type K.

source

pub fn determinant(&self) -> K

Computes the determinant of the matrix, supporting dimensions from 1x1 to 4x4.

§Formula
determinant formula

For matrices with dimensions 1x1 to 4x4, the determinant is computed based on the matrix size:

  • 0: Returns zero.
  • 1x1: Returns the single element as the determinant.
  • 2x2: Uses the formula A[0][0] * A[1][1] - A[0][1] * A[1][0].
  • 3x3: Uses cofactor expansion on the 3x3 matrix.
  • 4x4: Uses cofactor expansion along the first row on the 4x4 matrix.
§Returns

A value of type K representing the determinant of the matrix.

§Panics

Panics if the matrix is not square or if its dimensions exceed 4x4.

§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![1.0, 2.0],
    vec![3.0, 4.0]
]);
assert_eq!(mat.determinant(), -2.0);

Understanding the Determinant and it's Geometric Meaning

§Understanding Determinants and it’s Geometric Meaning

The determinant of a square matrix A, denoted as det(A), is a scalar value that can tell us a lot about the matrix and its associated linear transformation. To explain in detail, we need to break it down into two major concepts: linear transformations and geometry.

§Linear Transformations

A matrix A represents a linear transformation in a vector space. A linear transformation takes vectors from one vector space and maps them to another (or possibly the same) vector space, while preserving certain properties like vector addition and scalar multiplication.

Consider the matrix A acting on a vector v in a 2D or 3D space. When you multiply the matrix A by the vector v, you get a new vector A * v, which is the transformed version of v.

  • In 2D space, for example, a linear transformation could rotate, scale, shear, or reflect a vector.
  • In 3D space, it could also stretch or compress the space, or rotate and reflect it.
§The Determinant and What It Tells Us

Now, the determinant of the matrix gives us some very important information about this transformation:

  1. Scaling Factor: The determinant tells us how much the linear transformation changes the volume or area (in 2D) of the space.

    • In 2D, the determinant tells us by how much the area of any shape (like a square or triangle) is scaled when the transformation is applied. If the determinant is 2, for example, the area of any shape is doubled.
    • In 3D, it tells us by how much the volume is scaled.
  2. Invertibility: The determinant also tells us whether the transformation is invertible (i.e., whether you can reverse the transformation). If det(A) = 0, the transformation is not invertible. This means that the transformation “collapses” the space in some way, making it impossible to reverse the process. The vectors get “squashed” into a lower-dimensional space.

    • In 2D, for instance, if the determinant is zero, a shape like a square could be transformed into a line or even a point (a collapse from 2D to 1D or 0D).
    • In 3D, if det(A) = 0, a solid object (like a cube) could be collapsed into a plane, a line, or even a point.
  3. Orientation: The sign of the determinant tells us whether the transformation preserves or reverses orientation. If the determinant is positive, the transformation preserves orientation. If it’s negative, the transformation reverses orientation (for example, like flipping a shape over).

§What Happens When det(A) = 0?

When det(A) = 0, we have a very special situation:

  • The linear transformation collapses the space into a lower-dimensional subspace. This means that if you apply this transformation to any set of vectors, the result will always lie in a smaller-dimensional subspace.
    • In 2D, for instance, if the determinant is zero, the transformation might map every vector to a line or even a single point. The area of any shape becomes zero because all the points are squeezed onto a lower-dimensional object.
    • In 3D, if det(A) = 0, the transformation could collapse a 3D object into a 2D plane, a 1D line, or a point. The volume becomes zero because the space has lost one or more dimensions.
§Geometric Explanation of det(A) = 0 with Examples

Let’s take some simple examples to visualize what happens when the determinant is zero:

§1. 2D Case:

Suppose we have the following matrix A that represents a linear transformation in 2D:

A = [ 2  4 ]
    [ 1  2 ]

The determinant of A is:

det(A) = (2 * 2) - (1 * 4) = 4 - 4 = 0

This means the transformation represented by A collapses the 2D plane into a line. If we apply this matrix to a square, it will become a degenerate shape (a line), and the area of the square will become zero.

Why is this? Because the columns of the matrix are linearly dependent (the second column is just a multiple of the first column). So, the transformation doesn’t preserve the 2D structure and squashes the space.

§2. 3D Case:

Now consider a 3D example:

A = [ 1  2  3 ]
    [ 0  0  0 ]
    [ 4  5  6 ]

The determinant is zero:

det(A) = 1 * det([0 0] [5 6]) - 2 * det([0 0] [4 6]) + 3 * det([0 0] [4 5]) = 0

The second row of the matrix is all zeros, which means that this matrix represents a transformation that collapses all 3D space onto a plane (since we lose a degree of freedom by squashing one of the dimensions). As a result, the volume becomes zero.

Why is this? The rows (or columns) of the matrix are not linearly independent, meaning the transformation maps the entire 3D space onto a lower-dimensional subspace, in this case, a 2D plane.

§Summary
  • The determinant of a matrix is a scalar value that represents how much a linear transformation scales the volume or area of objects.
  • If det(A) ≠ 0, the transformation preserves the space’s dimensionality (it’s invertible).
  • If det(A) = 0, the transformation collapses the space into a lower dimension, and the transformation is not invertible. This leads to a loss of volume or area, depending on the dimension.
  • Geometrically, det(A) = 0 means the linear transformation reduces the space’s dimensionality (e.g., from 3D to 2D, or from 2D to 1D).

In conclusion, the determinant is a measure of how the transformation behaves geometrically, especially in terms of scaling, collapsing, and invertibility. A determinant of zero indicates a collapse of space, which makes the transformation non-reversible and non-invertible.

source

pub fn inverse(&self) -> Result<Matrix<K>, &'static str>

Computes the inverse of a square matrix, if it exists.

For a given square matrix A, the inverse matrix A^-1 is defined such that:

inverse property A * A^-1 = A^-1 * A = I

where I is the identity matrix of the same dimension as A. The identity matrix I has 1s on the diagonal and 0s elsewhere. Only non-singular matrices (matrices with a non-zero determinant) have an inverse. If the matrix is singular (determinant is zero), this function returns an error.

§Formula

For a matrix A of dimension n x n, the inverse matrix A^-1 can be calculated using:

inverse formula A^-1 = (1 / det(A)) * adj(A)

where:

  • det(A) is the determinant of A.
  • adj(A) is the adjugate (or adjoint) of A.
§Steps to Calculate the Adjugate adj(A)
adjoint formula

The adjugate matrix adj(A) is obtained by:

  1. Computing the Matrix of Minors: Each element M[i][j] in the matrix of minors is the determinant of the (n-1)x(n-1) submatrix that remains after removing the i-th row and j-th column of A.

  2. Applying Cofactor Signs: For each element M[i][j], we apply the cofactor sign:

    cofactor formula C[i][j] = (-1)^(i+j) * M[i][j]

    This results in the cofactor matrix C.

  3. Taking the Transpose: The adjugate adj(A) is the transpose of the cofactor matrix C, where each element adj(A)[j][i] is assigned the value C[i][j].

§Complete Formula for Each Element of the Inverse

Once the adjugate matrix adj(A) is calculated, we obtain the inverse A^-1 by dividing each element in adj(A) by det(A). Thus:

A^-1[i][j] = adj(A)[i][j] / det(A)
§Errors
  • Returns Err("Matrix is singular and cannot be inverted.") if the matrix has a zero determinant, meaning it has no inverse.
§Panics
  • Panics if the matrix is not square, as inversion is only defined for square matrices.
§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![4.0, 7.0],
    vec![2.0, 6.0],
]);

let inverse = mat.inverse().expect("Matrix is singular and cannot be inverted.");

assert_eq!(inverse, Matrix::new(vec![
    vec![0.6, -0.7],
    vec![-0.2, 0.4],
]));
source

pub fn rank(&self) -> usize

Computes the rank of a matrix using row echlon method.

The rank of a matrix is equal to the number of linearly independent rows in it. Hence, it cannot be more than its number of rows and columns. The best rank a matrix can have is equal to the number of rows.

§Steps to Calculate the rank
  1. Compute the reduced row echlon matrix.
  2. Count all the linear independent rows that is the non zero rows.
  3. The number of rows counted is the rank..
§Panics
  • Panics if the matrix is not rectangular, cannot compute row echlon of non rectangular matrices.
§Example
use matrix::Matrix;

let mat = Matrix::new(vec![
    vec![4.0, 7.0],
    vec![2.0, 6.0],
    vec![2.0, 6.0],
]);

assert_eq!(mat.rank(), 2);

Trait Implementations§

source§

impl<K: Scalar> AddAssign for Matrix<K>

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl<K: Clone + Scalar> Clone for Matrix<K>

source§

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

Returns a copy 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<K: Debug + Scalar> Debug for Matrix<K>

source§

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

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

impl<K: Scalar + Display> Display for Matrix<K>

source§

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

Implement fmt to display a matrix whenever you want

§Example
use matrix::Matrix;

let m = Matrix::from([
    [2., 3.],
    [4., 5.],
]);
println!("{}", m);
// [2.0, 3.0]
// [4.0, 5.0]
source§

impl<K: Scalar, const N: usize, const M: usize> From<[[K; M]; N]> for Matrix<K>

source§

fn from(array: [[K; M]; N]) -> Self

The From trait is implemented to convert a 2D array [[K; M]; N] into a Matrix<K>. The function takes a 2D array (with N rows and M columns) and creates a Matrix<K> by converting it into a Vec<Vec<K>>, where each row of the matrix is a Vec<K>.

§Example
use matrix::Matrix;

let u = Matrix::from([
    [8., 5., -2.],
    [4., 7., 20.],
    [7., 6., 1.],
]);
use matrix::Matrix;

let u = Matrix::from([
    [2., 0., 0.],
    [0., 2., 0.],
]);
source§

impl<K: Scalar> MulAssign<K> for Matrix<K>

source§

fn mul_assign(&mut self, scalar: K)

Performs the *= operation. Read more
source§

impl<K: Scalar> PartialEq for Matrix<K>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<K: Scalar> SubAssign for Matrix<K>

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<K> Freeze for Matrix<K>

§

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

§

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

§

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

§

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

§

impl<K> UnwindSafe for Matrix<K>
where K: 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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

§

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§

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

§

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

§

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.