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>
impl<F: Field, V: Vector<F = F>, const N: usize> Matrix<V, N>
Sourcepub fn new(m: [[F; N]; N]) -> Self
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.
Sourcepub fn mul_dual_v(&self, v: &Dual<V>) -> Dual<V>
pub fn mul_dual_v(&self, v: &Dual<V>) -> Dual<V>
The contraction V* ⊗ (V ⊗ V*) -> V*
Sourcepub fn flat_iter<'a>(&'a self) -> impl Iterator<Item = &'a F>where
F: 'a,
pub fn flat_iter<'a>(&'a self) -> impl Iterator<Item = &'a F>where
F: 'a,
Iterates all N² entries in row-major order.
Sourcepub fn destructure<const M: usize>(&self) -> [[F; M]; M]
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.
Sourcepub fn solve(&self, rhs: Self) -> Self
pub fn solve(&self, rhs: Self) -> Self
Solves A * X = B by Gauss–Jordan elimination.
Assumes A is invertible.
Sourcepub fn inverse(&self) -> Self
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>
impl<F: Field + Metric, V: Vector<F = F>, const N: usize> Matrix<V, N>
Sourcepub fn frobenius_norm(&self) -> F::R
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.
pub fn one_norm(&self) -> F::R
Sourcepub fn solve_pivoted(&self, rhs: Self) -> Self
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.
pub fn inverse_pivoted(&self) -> Self
Trait Implementations§
impl<V: Copy + Vector, const N: usize> Copy for Matrix<V, N>
Source§impl<const N: usize, F: Field<Characteristic = NatZero> + Metric + FromReal + FieldExp, V: Vector<F = F>> MatrixExponential for Matrix<V, N>
impl<const N: usize, F: Field<Characteristic = NatZero> + Metric + FromReal + FieldExp, V: Vector<F = F>> MatrixExponential for Matrix<V, N>
Auto Trait Implementations§
impl<V, const N: usize> Freeze for Matrix<V, N>
impl<V, const N: usize> RefUnwindSafe for Matrix<V, N>
impl<V, const N: usize> Send for Matrix<V, N>
impl<V, const N: usize> Sync for Matrix<V, N>
impl<V, const N: usize> Unpin for Matrix<V, N>
impl<V, const N: usize> UnsafeUnpin for Matrix<V, N>
impl<V, const N: usize> UnwindSafe for Matrix<V, N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<G> CGroup for G
impl<G> CGroup for G
fn check_left_inverse(&self) -> boolwhere
Self: PartialEq,
fn check_right_inverse(&self) -> boolwhere
Self: PartialEq,
fn check_sub_agrees_with_neg(a: &Self, b: &Self) -> boolwhere
Self: PartialEq,
Source§impl<M> CMonoid for M
impl<M> CMonoid for M
fn check_left_identity(&self) -> boolwhere
Self: PartialEq,
fn check_right_identity(&self) -> boolwhere
Self: PartialEq,
fn check_associativity(a: Self, b: Self, c: Self) -> boolwhere
Self: PartialEq,
fn check_commutativity(a: Self, b: Self) -> boolwhere
Self: PartialEq,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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