Module solveh

Source
Expand description

Solve Hermitian (or real symmetric) linear problems and invert Hermitian (or real symmetric) matrices

Note that only the upper triangular portion of the matrix is used.

§Examples

Solve A * x = b, where A is a Hermitian (or real symmetric) matrix:

use ndarray::prelude::*;
use ndarray_linalg::SolveH;

let a: Array2<f64> = array![
    [3., 2., -1.],
    [2., -2., 4.],
    [-1., 4., 5.]
];
let b: Array1<f64> = array![11., -12., 1.];
let x = a.solveh_into(b).unwrap();
assert!(x.abs_diff_eq(&array![1., 3., -2.], 1e-9));

If you are solving multiple systems of linear equations with the same Hermitian or real symmetric coefficient matrix A, it’s faster to compute the factorization once at the beginning than solving directly using A:

use ndarray::prelude::*;
use ndarray_linalg::*;

/// Use fixed algorithm and seed of PRNG for reproducible test
let mut rng = rand_pcg::Mcg128Xsl64::new(0xcafef00dd15ea5e5);

let a: Array2<f64> = random_using((3, 3), &mut rng);
let f = a.factorizeh_into().unwrap(); // Factorize A (A is consumed)
for _ in 0..10 {
    let b: Array1<f64> = random_using(3, &mut rng);
    let x = f.solveh_into(b).unwrap(); // Solve A * x = b using the factorization
}

Structs§

BKFactorized
Represents the Bunch–Kaufman factorization of a Hermitian (or real symmetric) matrix as A = P * U * D * U^H * P^T.

Enums§

UPLO
Upper/Lower specification for seveal usages

Traits§

DeterminantH
An interface for calculating determinants of Hermitian (or real symmetric) matrix refs.
DeterminantHInto
An interface for calculating determinants of Hermitian (or real symmetric) matrices.
FactorizeH
An interface for computing the Bunch–Kaufman factorization of Hermitian (or real symmetric) matrix refs.
FactorizeHInto
An interface for computing the Bunch–Kaufman factorization of Hermitian (or real symmetric) matrices.
InverseH
An interface for inverting Hermitian (or real symmetric) matrix refs.
InverseHInto
An interface for inverting Hermitian (or real symmetric) matrices.
SolveH
An interface for solving systems of Hermitian (or real symmetric) linear equations.

Type Aliases§

Pivot