Struct Matrix

Source
pub struct Matrix<F: Field> { /* private fields */ }

Implementations§

Source§

impl<F: Field> Matrix<F>

Source

pub fn new(matrix: Vec<Vec<F>>) -> Matrix<F>

Creates a new matrix from a vector of vectors.

§Example
let a: Matrix<F> = Matrix::new(vec![
    vec![F::from(2), F::from(2)],
    vec![F::from(3), F::from(4)],
]);
Source

pub fn is_square(self) -> bool

Returns whether or not the matrix is square.

§Example
let is_square: bool = a.is_square();
assert!(is_square);
Source

pub fn determinant(self) -> F

Returns the determinant of the matrix.

§Example
let det: F = a.determinant();
Source

pub fn is_diagonal(self) -> bool

Returns whether or not the matrix is diagonal.

§Example
let is_diagonal: bool = a.is_diagonal();
assert!(is_diagonal);
Source

pub fn transpose(self) -> Matrix<F>

Returns the transpose of the matrix.

§Example
let b: Matrix<F> = a.transpose();
Source

pub fn adjoint(self) -> Matrix<F>

Returns the adjoint of the matrix.

§Example
let b: Matrix<F> = a.adjoint();
Source

pub fn inverse(self) -> Option<Matrix<F>>

Returns the inverse of the matrix.

§Example
let b: Matrix<F> = a.inverse();
§Panics

Panics if the matrix is not invertible.

§Notes

This function uses the LU decomposition to compute the inverse. The LU decomposition is computed using the Doolittle algorithm.

Source

pub fn is_identity(self) -> bool

Returns whether or not the matrix is the identity matrix.

§Example
let is_identity: bool = a.is_identity();
assert!(is_identity);
§Notes

This function returns false if the matrix is empty.

Source

pub fn ax_b_solve_for_x(self, b: Vec<F>) -> Vec<F>

Solves the system of linear equations Ax = b for x.

§Example
let x: Vec<F> = a.solve_for_x(b);
§Panics

Panics if the matrix is the determinant of the matrix is zero.

§Notes

This function uses the LU decomposition to solve the system of linear equations. The LU decomposition is computed using the Doolittle algorithm.

Source

pub fn lu_decomposition(&self) -> (Matrix<F>, Matrix<F>)

Returns the LU decomposition of the matrix.

§Example
let (l, u): (Matrix<F>, Matrix<F>) = a.lu_decomposition();
§Panics

Panics if the matrix is the determinant of the matrix is zero.

§Notes

This function uses the Doolittle algorithm to compute the LU decomposition. The Doolittle algorithm is a variant of the Gaussian elimination algorithm.

Source

pub fn scalar_mul(self, scalar: F) -> Matrix<F>

Multiplies the matrix by a scalar.

§Example
let c: Matrix<F> = a.scalar_mul(b);
§Notes

This function is equivalent to multiplying each element of the matrix by the scalar.

Source

pub fn mul_vec(self, vec: Vec<F>) -> Vec<F>

Multiplies the matrix by a vector.

§Example
let c: Vec<F> = a.mul_vec(b);
§Panics

Panics if the number of rows in the matrix is not equal to the number of elements in the vector.

§Notes

This function is equivalent to multiplying the matrix by a column vector.

Source

pub fn sum_of_matrix(self) -> F

Returns the sum of all the elements in the matrix.

§Example
let c: F = a.sum_of_matrix();
§Notes

This function is equivalent to summing all the elements in the matrix.

Source

pub fn set_element(&mut self, row: usize, column: usize, new_value: F)

Sets a specific element in the matrix.

§Example
type F = Field;
let a: Matrix<F> = Matrix::new(vec![
    vec![F::from(2), F::from(2)],
    vec![F::from(3), F::from(4)],
]);
a.set_element(0, 0, F::from(1));
§Panics

Panics if the row or column is out of bounds.

§Notes

This function is equivalent to setting the element in the matrix. With row being the position in the outer vector and column being the position in the inner vector. The first element in the outer vector is row 0 and the first element in the inner vector is column 0.

Source

pub fn get_element(&self, row: usize, column: usize) -> F

Gets a specific element in the matrix.

§Example
let a: Matrix<F> = Matrix::new(vec![
  vec![F::from(2), F::from(2)],
  vec![F::from(3), F::from(4)],
]);
let b: F = a.get_element(0, 0);
assert_eq!(b, F::from(2));
§Panics

Panics if the row or column is out of bounds.

§Notes

This function is equivalent to getting the element in the matrix. With row being the position in the outer vector and column being the position in the inner vector. The first element in the outer vector is row 0 and the first element in the inner vector is column 0.

Trait Implementations§

Source§

impl<F: Field> Add for Matrix<F>

Source§

type Output = Matrix<F>

The resulting type after applying the + operator.
Source§

fn add(self, other: Matrix<F>) -> Matrix<F>

Performs the + operation. Read more
Source§

impl<F: Clone + Field> Clone for Matrix<F>

Source§

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

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<F: Debug + Field> Debug for Matrix<F>

Source§

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

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

impl<F: Field> Display for Matrix<F>

Source§

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

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

impl<F: Field> Mul for Matrix<F>

Source§

type Output = Matrix<F>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Matrix<F>) -> Matrix<F>

Performs the * operation. Read more
Source§

impl<F: Field> PartialEq for Matrix<F>

Source§

fn eq(&self, other: &Matrix<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Field> Sub for Matrix<F>

Source§

type Output = Matrix<F>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Matrix<F>) -> Matrix<F>

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<F> Freeze for Matrix<F>

§

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

§

impl<F> Send for Matrix<F>

§

impl<F> Sync for Matrix<F>

§

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

§

impl<F> UnwindSafe for Matrix<F>
where F: 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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V