Skip to main content

Matrix

Struct Matrix 

Source
pub struct Matrix<const R: usize, const C: usize> { /* private fields */ }
Expand description

Dense R × C f64 matrix.

Implementations§

Source§

impl<const R: usize, const C: usize> Matrix<R, C>

Source

pub const ZERO: Self

Zero matrix.

Source

pub const fn from_rows(rows: [[f64; C]; R]) -> Self

From rows.

Source

pub fn from_fn(element: impl FnMut(usize, usize) -> f64) -> Self

Element (row, column) from a closure.

Source

pub const fn rows(&self) -> &[[f64; C]; R]

Rows.

Source

pub fn get(&self, row: usize, column: usize) -> Option<f64>

Element at (row, column); None outside.

Source

pub fn set(&mut self, row: usize, column: usize, value: f64) -> bool

Sets element (row, column); returns false and does nothing outside the matrix.

Source

pub fn transpose(&self) -> Matrix<C, R>

Transpose.

Source

pub fn scaled(&self, factor: f64) -> Self

Scalar multiple.

Source

pub fn is_finite(&self) -> bool

Whether all elements are finite.

Source

pub fn max_abs(&self) -> f64

Maximum absolute element.

Source§

impl<const N: usize> Matrix<N, N>

Source

pub fn identity() -> Self

Identity.

Source

pub fn diagonal(values: [f64; N]) -> Self

Diagonal matrix.

Source

pub fn trace(&self) -> f64

Trace.

Source

pub fn symmetrised(&self) -> Self

(A + Aᵀ) / 2: exactly symmetric; unchanged for a symmetric input.

Removes the last-place asymmetries a covariance accumulates through products.

Source

pub fn cholesky(&self) -> Option<Cholesky<N>>

Cholesky factor L with self = L Lᵀ; None unless symmetric positive definite.

A pivot ≤ 0 within a matrix-scaled tolerance (an unobserved state can have exactly zero variance) means not positive definite; the result is None, not a factor of NaNs. Non-iterative: N³/6 operations.

Source

pub fn is_covariance(&self) -> bool

Whether symmetric (relative tolerance) and positive semi-definite, as judged by Matrix::cholesky.

Source§

impl<const N: usize> Matrix<N, 1>

Source

pub fn from_column(values: [f64; N]) -> Self

From elements.

Source

pub fn to_column(&self) -> [f64; N]

Elements.

Source

pub fn element(&self, row: usize) -> Option<f64>

Element at row; None outside.

Source

pub fn dot(&self, other: &Self) -> f64

Dot product.

Source

pub fn norm(&self) -> f64

Euclidean norm.

Trait Implementations§

Source§

impl<const R: usize, const C: usize> Add for Matrix<R, C>

Source§

type Output = Matrix<R, C>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl<const R: usize, const C: usize> Clone for Matrix<R, C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<const R: usize, const C: usize> Copy for Matrix<R, C>

Source§

impl<const R: usize, const C: usize> Debug for Matrix<R, C>

Source§

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

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

impl<const R: usize, const K: usize, const C: usize> Mul<Matrix<K, C>> for Matrix<R, K>

Source§

type Output = Matrix<R, C>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Matrix<K, C>) -> Matrix<R, C>

Performs the * operation. Read more
Source§

impl<const R: usize, const C: usize> PartialEq for Matrix<R, C>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<const R: usize, const C: usize> StructuralPartialEq for Matrix<R, C>

Source§

impl<const R: usize, const C: usize> Sub for Matrix<R, C>

Source§

type Output = Matrix<R, C>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<const R: usize, const C: usize> Freeze for Matrix<R, C>
where [[f64; C]; R]: Freeze,

§

impl<const R: usize, const C: usize> RefUnwindSafe for Matrix<R, C>
where [[f64; C]; R]: RefUnwindSafe,

§

impl<const R: usize, const C: usize> Send for Matrix<R, C>
where [[f64; C]; R]: Send,

§

impl<const R: usize, const C: usize> Sync for Matrix<R, C>
where [[f64; C]; R]: Sync,

§

impl<const R: usize, const C: usize> Unpin for Matrix<R, C>
where [[f64; C]; R]: Unpin,

§

impl<const R: usize, const C: usize> UnsafeUnpin for Matrix<R, C>
where [[f64; C]; R]: UnsafeUnpin,

§

impl<const R: usize, const C: usize> UnwindSafe for Matrix<R, C>
where [[f64; C]; R]: 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.