pub struct Ldlt<const D: usize> { /* private fields */ }Expand description
LDLT factorization (A = L D Lᵀ) for symmetric positive (semi)definite matrices.
This factorization is not a general-purpose symmetric-indefinite LDLT (no pivoting). It assumes the input matrix is symmetric and (numerically) SPD/PSD.
§Storage
The factors are stored in a single Matrix:
Dis stored on the diagonal.- The strict lower triangle stores the multipliers of
L. - The diagonal of
Lis implicit ones.
Implementations§
Source§impl<const D: usize> Ldlt<D>
impl<const D: usize> Ldlt<D>
Sourcepub fn det(&self) -> f64
pub fn det(&self) -> f64
Determinant of the original matrix.
For SPD/PSD matrices, this is the product of the diagonal terms of D.
§Examples
use la_stack::prelude::*;
// Symmetric SPD matrix.
let a = Matrix::<2>::from_rows([[4.0, 2.0], [2.0, 3.0]]);
let ldlt = a.ldlt(DEFAULT_SINGULAR_TOL).unwrap();
assert!((ldlt.det() - 8.0).abs() <= 1e-12);Sourcepub fn solve_vec(&self, b: Vector<D>) -> Result<Vector<D>, LaError>
pub fn solve_vec(&self, b: Vector<D>) -> Result<Vector<D>, LaError>
Solve A x = b using this LDLT factorization.
§Examples
use la_stack::prelude::*;
let a = Matrix::<2>::from_rows([[4.0, 2.0], [2.0, 3.0]]);
let ldlt = a.ldlt(DEFAULT_SINGULAR_TOL)?;
let b = Vector::<2>::new([1.0, 2.0]);
let x = ldlt.solve_vec(b)?.into_array();
assert!((x[0] - (-0.125)).abs() <= 1e-12);
assert!((x[1] - 0.75).abs() <= 1e-12);§Errors
Returns LaError::Singular if a diagonal entry d = D[i,i] satisfies d <= tol
(non-positive or too small), where tol is the tolerance that was used during factorization.
Returns LaError::NonFinite if NaN/∞ is detected.
Trait Implementations§
impl<const D: usize> Copy for Ldlt<D>
impl<const D: usize> StructuralPartialEq for Ldlt<D>
Auto Trait Implementations§
impl<const D: usize> Freeze for Ldlt<D>
impl<const D: usize> RefUnwindSafe for Ldlt<D>
impl<const D: usize> Send for Ldlt<D>
impl<const D: usize> Sync for Ldlt<D>
impl<const D: usize> Unpin for Ldlt<D>
impl<const D: usize> UnwindSafe for Ldlt<D>
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
Mutably borrows from an owned value. Read more