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.
§Preconditions
The source matrix passed to Matrix::ldlt must be
symmetric (A[i][j] == A[j][i] within rounding). Asymmetric inputs return
LaError::Asymmetric before factorization starts; see
Matrix::ldlt for details and alternatives.
§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 const fn det(&self) -> Result<f64, LaError>
pub const fn det(&self) -> Result<f64, LaError>
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>::try_from_rows([[4.0, 2.0], [2.0, 3.0]])?;
let ldlt = a.ldlt(DEFAULT_SINGULAR_TOL)?;
assert!((ldlt.det()? - 8.0).abs() <= 1e-12);§Errors
Returns LaError::NonFinite if the determinant product overflows to
NaN or infinity.
Sourcepub const fn solve_vec(&self, b: Vector<D>) -> Result<Vector<D>, LaError>
pub const fn solve_vec(&self, b: Vector<D>) -> Result<Vector<D>, LaError>
Solve A x = b using this LDLT factorization.
solve_vec performs floating-point substitution and does not provide a
certified absolute rounding-error bound for the returned solution.
§Examples
use la_stack::prelude::*;
let a = Matrix::<2>::try_from_rows([[4.0, 2.0], [2.0, 3.0]])?;
let ldlt = a.ldlt(DEFAULT_SINGULAR_TOL)?;
let b = Vector::<2>::try_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::NonFinite if the right-hand side contains
NaN/infinity or a computed substitution intermediate overflows to NaN or
infinity. The right-hand side is revalidated at this boundary before
entering substitution; public callers normally encounter the same
rejection earlier through Vector::try_new.