Skip to main content

Ldlt

Struct Ldlt 

Source
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:

  • D is stored on the diagonal.
  • The strict lower triangle stores the multipliers of L.
  • The diagonal of L is implicit ones.

Implementations§

Source§

impl<const D: usize> Ldlt<D>

Source

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.

Source

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.

Trait Implementations§

Source§

impl<const D: usize> Clone for Ldlt<D>

Source§

fn clone(&self) -> Ldlt<D>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const D: usize> Copy for Ldlt<D>

Source§

impl<const D: usize> Debug for Ldlt<D>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const D: usize> PartialEq for Ldlt<D>

Source§

fn eq(&self, other: &Ldlt<D>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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> UnsafeUnpin for Ldlt<D>

§

impl<const D: usize> UnwindSafe for Ldlt<D>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.