ldlt_decomposition

Function ldlt_decomposition 

Source
pub fn ldlt_decomposition<T, S>(
    matrix: &S,
    pivoting: Option<bool>,
    threshold: Option<T>,
) -> SparseResult<LDLTResult<T>>
where T: Float + SparseElement + Debug + Copy + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>, S: SparseArray<T>,
Expand description

Compute LDLT decomposition for symmetric indefinite matrices

Computes the LDLT decomposition of a symmetric matrix A = P^T * L * D * L^T * P, where P is a permutation matrix, L is unit lower triangular, and D is diagonal. This method can handle indefinite matrices unlike Cholesky decomposition.

§Arguments

  • matrix - The symmetric sparse matrix
  • pivoting - Whether to use pivoting for numerical stability (default: true)
  • threshold - Pivoting threshold for numerical stability (default: 1e-12)

§Returns

LDLT decomposition result

§Examples

use scirs2_sparse::linalg::ldlt_decomposition;
use scirs2_sparse::csr_array::CsrArray;

// Create a symmetric indefinite matrix
let rows = vec![0, 1, 1, 2, 2, 2];
let cols = vec![0, 0, 1, 0, 1, 2];  
let data = vec![1.0, 2.0, -1.0, 3.0, 1.0, 2.0];
let matrix = CsrArray::from_triplets(&rows, &cols, &data, (3, 3), false).unwrap();

let ldlt_result = ldlt_decomposition(&matrix, Some(true), Some(1e-12)).unwrap();