added test for update

This commit is contained in:
Nestor Demeure 2019-11-02 15:11:14 +01:00
parent 2beb09dab2
commit 1fe4ef956b
1 changed files with 16 additions and 1 deletions

View File

@ -1,6 +1,5 @@
#![cfg(all(feature = "arbitrary", feature = "debug"))]
macro_rules! gen_tests(
($module: ident, $scalar: ty) => {
mod $module {
@ -78,6 +77,22 @@ macro_rules! gen_tests(
id1.is_identity(1.0e-7) && id2.is_identity(1.0e-7)
}
fn cholesky_rank_one_update(_n: usize) -> bool {
let m = RandomSDP::new(U4, || random::<$scalar>().0).unwrap();
let x = Vector4::<$scalar>::new_random().map(|e| e.0);
let sigma : $scalar = 1.;
// updates m manually
let m_updated = m + sigma * x * x.transpose();
// updates cholesky deomposition and reconstruct m
let mut chol = m.clone().cholesky().unwrap();
chol.rank_one_update(x, sigma);
let m_chol_updated = chol.l() * chol.l().transpose();
relative_eq!(m_updated, m_chol_updated, epsilon = 1.0e-7)
}
}
}
}