Skip to main content

cholesky_update

Function cholesky_update 

Source
pub fn cholesky_update<B: Backend, T: LinalgFloat>(
    r: &Array<B, T>,
    w: &Array<B, T>,
) -> Array<B, T>
Expand description

The rank-1 update of a Cholesky factorization, as lax.linalg.cholesky_update: given the upper triangular r of a = r^T r and the vector w, the upper triangular factor of a + w w^T in O(n^2) (by Givens rotations, as JAX computes it on CPU; the diagonal may come out negative). Real matrices only, not differentiable, as in JAX.

§Examples

use ruxla_core::{Array, Native, lax::linalg::cholesky_update};

// a = r^T r = [[4, 2], [2, 5]]; a + w w^T = [[5, 4], [4, 9]].
let r = Array::<Native, f64>::from_vec(vec![2.0, 1.0, 0.0, 2.0], [2, 2]);
let w = Array::<Native, f64>::from_vec(vec![1.0, 2.0], [2]);
let r = cholesky_update(&r, &w).to_vec();
let a = [
    r[0] * r[0],
    r[0] * r[1],
    r[1] * r[1] + r[3] * r[3],
];
for (got, expected) in a.iter().zip([5.0, 4.0, 9.0]) {
    assert!((got - expected).abs() < 1e-12);
}

§Panics

Panics if r is not square or w does not match it.