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 panic in debug builds via
debug_assert! and are silently accepted in release builds — producing a
mathematically meaningless factorization whose Self::det and Self::solve_vec
results are wrong without any error being reported. Pre-validate with
Matrix::is_symmetric when the input cannot be
statically guaranteed symmetric; see Matrix::ldlt for further
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) -> f64
pub const 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 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.
§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. The row/col coordinates
follow the convention documented on LaError::NonFinite:
row: Some(i), col: i— the storedDdiagonal at(i, i)is non-finite (only reachable via directLdltconstruction;Matrix::ldltrejects such factorizations).row: None, col: i— a computed intermediate (forward/back-substitution accumulator or the quotientx[i] / diag) overflowed to NaN/∞ at stepi.