pub struct Ldlt<const D: usize> { /* private fields */ }Expand description
LDLT factorization (A = L D Lᵀ) for symmetric positive (semi)definite matrices.
Ldlt<0> represents the empty factorization. Its determinant is the empty
product 1.0, and solving against Vector<0> returns Vector<0>.
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(&self, b: Vector<D>) -> Result<Vector<D>, LaError>
pub const fn solve(&self, b: Vector<D>) -> Result<Vector<D>, LaError>
Solve A x = b using this LDLT factorization.
Vector is finite by construction, so this method only checks computed
substitution overflows. It 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(b)?.into_array();
assert!((x[0] - (-0.125)).abs() <= 1e-12);
assert!((x[1] - 0.75).abs() <= 1e-12);§Errors
Returns LaError::NonFinite if a computed substitution intermediate
overflows to NaN or infinity.