Expand description
Cholesky factorization and linear solves for symmetric positive-definite matrices.
This module provides a CholeskyFactorizer type for computing and storing the
Cholesky factorization of a square matrix
$$A = L L^\intercal$$
where $L$ is lower triangular.
The matrix is provided as a flat slice in row-major order. Internally, the
computed Cholesky factor L is also stored in row-major order in a dense
Vec<T>. Only the lower-triangular part is meaningful after factorization.
Once a factorization has been computed with CholeskyFactorizer::factorize,
the stored factor can be reused to solve linear systems of the form
$$A x = b$$
via CholeskyFactorizer::solve.
§Requirements
The input matrix must:
- be square of dimension
n × n - be stored in row-major order
- be symmetric positive definite
If the matrix is not positive definite, factorization fails with
CholeskyError::NotPositiveDefinite.
§Errors
The module uses CholeskyError to report the following conditions:
CholeskyError::DimensionMismatchwhen the input matrix or right-hand side has an incompatible sizeCholeskyError::NotPositiveDefinitewhen factorization fails because the matrix is not positive definiteCholeskyError::NotFactorizedwhen attempting to solve a system before a valid factorization has been computed
§Example
use optimization_engine::CholeskyFactorizer;
let a = vec![
4.0_f64, 1.0,
1.0, 3.0,
];
let b = vec![1.0_f64, 2.0];
let mut factorizer = CholeskyFactorizer::new(2);
factorizer.factorize(&a).unwrap();
let x = factorizer.solve(&b).unwrap();
assert!((x[0] - 0.0909090909).abs() < 1e-10);
assert!((x[1] - 0.6363636364).abs() < 1e-10);§Notes
- The implementation is generic over
T: Float. - Storage is preallocated when constructing the factorizer with
CholeskyFactorizer::new. - The factorizer keeps the computed factor internally so that multiple right-hand sides can be solved efficiently after a single factorization.
Structs§
- Cholesky
Factorizer - Cholesky factoriser
Enums§
- Cholesky
Error - Cholesky errors