Skip to main content

Matrix

Struct Matrix 

Source
pub struct Matrix<V: Vector, const N: usize>(/* private fields */);
Expand description

A matrix, interpreted as the (1, 1) tensor V ⊗ V*. N must be equal to V::N. This is enforced by all constructors at compile time. This is due to limitations in Rust’s const generics.

Implementations§

Source§

impl<F: Field, V: Vector<F = F>, const N: usize> Matrix<V, N>

Source

pub fn new(m: [[F; N]; N]) -> Self

Wraps a raw N×N array as a matrix, checking V::N == N at compile time. The const assertion is the crate’s stand-in for Matrix<V, {V::N}>, which stable const generics can’t express — it guarantees the matrix’s dimension matches the space it acts on.

Source

pub fn mul(&self, rhs: &Self) -> Self

The contraction (V ⊗ V*) ⊗ (V ⊗ V*) -> (V ⊗ V*)

Source

pub fn mul_v(&self, v: &V) -> V

The contraction (V ⊗ V*) ⊗ V -> V

Source

pub fn mul_dual_v(&self, v: &Dual<V>) -> Dual<V>

The contraction V* ⊗ (V ⊗ V*) -> V*

Source

pub fn transpose(self) -> Matrix<Dual<V>, N>

The transpose V ⊗ V* -> V* ⊗ V** ≅ V* ⊗ V

Source

pub fn flat_iter<'a>(&'a self) -> impl Iterator<Item = &'a F>
where F: 'a,

Iterates all entries in row-major order.

Source

pub fn trace(&self) -> F

The trace Σᵢ Mᵢᵢ — the contraction V ⊗ V* -> F.

Source

pub fn destructure<const M: usize>(&self) -> [[F; M]; M]

Extracts the raw entry array, checking N == M at compile time. Escape hatch back to a plain [[F; M]; M] for callers that need the components directly.

Source

pub fn solve(&self, rhs: Self) -> Self

Solves A * X = B by Gauss–Jordan elimination.

Assumes A is invertible.

Source

pub fn inverse(&self) -> Self

Inverts the matrix by Gauss–Jordan elimination.

Assumes invertibility: it panic!s on a zero pivot (a singular matrix). For an Sl element that panic is unreachable — determinant one is never singular — so this is a total operation on the special linear group, which is where it’s used.

Source§

impl<F: Field + Metric, V: Vector<F = F>, const N: usize> Matrix<V, N>

Source

pub fn frobenius_norm(&self) -> F::R

The Frobenius norm √(Σᵢⱼ |Mᵢⱼ|²), valued in the real field F::R.

Requires F: Metric so each entry has a definite squared magnitude (interval_squared against zero), keeping the sum a non-negative real. This is the norm the MatrixExponential Taylor series measures convergence against; it is submultiplicative, which is what makes that series converge.

Source

pub fn one_norm(&self) -> F::R

Source

pub fn solve_pivoted(&self, rhs: Self) -> Self

Solves A * X = B using Gauss–Jordan elimination with partial pivoting.

Pivot rows are chosen by maximizing the scalar metric magnitude. This improves numerical stability for approximate fields.

Assumes A is invertible.

Source

pub fn inverse_pivoted(&self) -> Self

Source§

impl<F: CField + Metric, V: Vector<F = F>, const N: usize> Matrix<V, N>

Source

pub fn det(&self) -> F

Trait Implementations§

Source§

impl<F: Field, V: Vector<F = F>, const N: usize> Add for Matrix<V, N>

Source§

type Output = Matrix<V, N>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<V: Clone + Vector, const N: usize> Clone for Matrix<V, N>
where V::F: Clone,

Source§

fn clone(&self) -> Matrix<V, N>

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<V: Copy + Vector, const N: usize> Copy for Matrix<V, N>
where V::F: Copy,

Source§

impl<V: Debug + Vector, const N: usize> Debug for Matrix<V, N>
where V::F: Debug,

Source§

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

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

impl<F: Field, V: Vector<F = F>, const N: usize> Div<F> for Matrix<V, N>

Source§

type Output = Matrix<V, N>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: F) -> Self::Output

Performs the / operation. Read more
Source§

impl<V: Vector, const N: usize> Index<(usize, usize)> for Matrix<V, N>

Source§

type Output = <V as Vector>::F

The returned type after indexing.
Source§

fn index(&self, index: (usize, usize)) -> &Self::Output

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

impl<V: Vector, const N: usize> IndexMut<(usize, usize)> for Matrix<V, N>

Source§

fn index_mut(&mut self, index: (usize, usize)) -> &mut Self::Output

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

impl<const N: usize, F: Field<Characteristic = NatZero> + Metric + FromReal + FieldExp, V: Vector<F = F>> MatrixExponential for Matrix<V, N>

Source§

fn exp(&self) -> Self

Source§

fn log(&self) -> Option<Self>

Source§

impl<F: Field, V: Vector<F = F>, const N: usize> Mul for Matrix<V, N>

Source§

type Output = Matrix<V, N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: Field, V: Vector<F = F>, const N: usize> Mul<F> for Matrix<V, N>

Source§

type Output = Matrix<V, N>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: F) -> Self::Output

Performs the * operation. Read more
Source§

impl<F: Field, V: Vector<F = F>, const N: usize> Neg for Matrix<V, N>

Source§

type Output = Matrix<V, N>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<F: Field, V: Vector<F = F>, const N: usize> One for Matrix<V, N>

Source§

fn one() -> Self

Returns the multiplicative identity element of Self, 1. Read more
Source§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<V: Vector, const N: usize> PartialEq for Matrix<V, N>

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<F: Field, V: Vector<F = F>, const N: usize> Sub for Matrix<V, N>

Source§

type Output = Matrix<V, N>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl<F: Field, V: Vector<F = F>, const N: usize> Zero for Matrix<V, N>

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.

Auto Trait Implementations§

§

impl<V, const N: usize> Freeze for Matrix<V, N>
where <V as Vector>::F: Freeze,

§

impl<V, const N: usize> RefUnwindSafe for Matrix<V, N>
where <V as Vector>::F: RefUnwindSafe,

§

impl<V, const N: usize> Send for Matrix<V, N>
where <V as Vector>::F: Send,

§

impl<V, const N: usize> Sync for Matrix<V, N>
where <V as Vector>::F: Sync,

§

impl<V, const N: usize> Unpin for Matrix<V, N>
where <V as Vector>::F: Unpin,

§

impl<V, const N: usize> UnsafeUnpin for Matrix<V, N>
where <V as Vector>::F: UnsafeUnpin,

§

impl<V, const N: usize> UnwindSafe for Matrix<V, N>
where <V as Vector>::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<G> CGroup for G
where G: Sub<Output = G> + Neg<Output = G> + CMonoid,

Source§

fn check_left_inverse(&self) -> bool
where Self: PartialEq,

Source§

fn check_right_inverse(&self) -> bool
where Self: PartialEq,

Source§

fn check_sub_agrees_with_neg(a: &Self, b: &Self) -> bool
where Self: PartialEq,

Source§

impl<M> CMonoid for M
where M: Point + Zero,

Source§

fn check_left_identity(&self) -> bool
where Self: PartialEq,

Source§

fn check_right_identity(&self) -> bool
where Self: PartialEq,

Source§

fn check_associativity(a: Self, b: Self, c: Self) -> bool
where Self: PartialEq,

Source§

fn check_commutativity(a: Self, b: Self) -> bool
where Self: PartialEq,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<M> Monoid for M
where M: Point + One,

Source§

fn check_left_identity(&self) -> bool
where Self: PartialEq,

Source§

fn check_right_identity(&self) -> bool
where Self: PartialEq,

Source§

fn check_associativity(a: Self, b: Self, c: Self) -> bool
where Self: PartialEq,

Source§

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

Source§

impl<R> Rig for R
where R: CMonoid + One,

Source§

fn check_left_distributivity(a: Self, b: Self, c: Self) -> bool
where Self: PartialEq,

Source§

fn check_right_distributivity(a: Self, b: Self, c: Self) -> bool
where Self: PartialEq,

Source§

fn check_left_annihilation(&self) -> bool
where Self: PartialEq,

Source§

fn check_right_annihilation(&self) -> bool
where Self: PartialEq,

Source§

impl<R> Ring for R
where R: CGroup + Rig,

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