pub struct Matrix<const D: usize> { /* private fields */ }Expand description
Fixed-size square matrix D×D, stored inline.
Implementations§
Source§impl<const D: usize> Matrix<D>
impl<const D: usize> Matrix<D>
Sourcepub const fn from_rows(rows: [[f64; D]; D]) -> Self
pub const fn from_rows(rows: [[f64; D]; D]) -> Self
Construct from row-major storage.
§Examples
use la_stack::prelude::*;
let m = Matrix::<2>::from_rows([[1.0, 2.0], [3.0, 4.0]]);
assert_eq!(m.get(0, 1), Some(2.0));Sourcepub const fn zero() -> Self
pub const fn zero() -> Self
All-zeros matrix.
§Examples
use la_stack::prelude::*;
let z = Matrix::<2>::zero();
assert_eq!(z.get(1, 1), Some(0.0));Sourcepub const fn identity() -> Self
pub const fn identity() -> Self
Identity matrix.
§Examples
use la_stack::prelude::*;
let i = Matrix::<3>::identity();
assert_eq!(i.get(0, 0), Some(1.0));
assert_eq!(i.get(0, 1), Some(0.0));
assert_eq!(i.get(2, 2), Some(1.0));Sourcepub const fn get(&self, r: usize, c: usize) -> Option<f64>
pub const fn get(&self, r: usize, c: usize) -> Option<f64>
Get an element with bounds checking.
§Examples
use la_stack::prelude::*;
let m = Matrix::<2>::from_rows([[1.0, 2.0], [3.0, 4.0]]);
assert_eq!(m.get(1, 0), Some(3.0));
assert_eq!(m.get(2, 0), None);Sourcepub const fn set(&mut self, r: usize, c: usize, value: f64) -> bool
pub const fn set(&mut self, r: usize, c: usize, value: f64) -> bool
Set an element with bounds checking.
Returns true if the index was in-bounds.
§Examples
use la_stack::prelude::*;
let mut m = Matrix::<2>::zero();
assert!(m.set(0, 1, 2.5));
assert_eq!(m.get(0, 1), Some(2.5));
assert!(!m.set(10, 0, 1.0));Sourcepub fn inf_norm(&self) -> f64
pub fn inf_norm(&self) -> f64
Infinity norm (maximum absolute row sum).
§Examples
use la_stack::prelude::*;
let m = Matrix::<2>::from_rows([[1.0, -2.0], [3.0, 4.0]]);
assert!((m.inf_norm() - 7.0).abs() <= 1e-12);Sourcepub fn lu(self, tol: f64) -> Result<Lu<D>, LaError>
pub fn lu(self, tol: f64) -> Result<Lu<D>, LaError>
Compute an LU decomposition with partial pivoting.
§Examples
use la_stack::prelude::*;
let a = Matrix::<2>::from_rows([[1.0, 2.0], [3.0, 4.0]]);
let lu = a.lu(DEFAULT_PIVOT_TOL)?;
let b = Vector::<2>::new([5.0, 11.0]);
let x = lu.solve_vec(b)?.into_array();
assert!((x[0] - 1.0).abs() <= 1e-12);
assert!((x[1] - 2.0).abs() <= 1e-12);§Errors
Returns LaError::Singular if no suitable pivot (|pivot| > tol) exists for a column.
Returns LaError::NonFinite if NaN/∞ is detected during factorization.
Trait Implementations§
impl<const D: usize> Copy for Matrix<D>
impl<const D: usize> StructuralPartialEq for Matrix<D>
Auto Trait Implementations§
impl<const D: usize> Freeze for Matrix<D>
impl<const D: usize> RefUnwindSafe for Matrix<D>
impl<const D: usize> Send for Matrix<D>
impl<const D: usize> Sync for Matrix<D>
impl<const D: usize> Unpin for Matrix<D>
impl<const D: usize> UnwindSafe for Matrix<D>
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)