From cc478c6c6d57183526df2dc0505cb7ccc270d768 Mon Sep 17 00:00:00 2001 From: Nestor Demeure Date: Sat, 2 Nov 2019 15:11:14 +0100 Subject: [PATCH] added test for update --- tests/linalg/cholesky.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/linalg/cholesky.rs b/tests/linalg/cholesky.rs index cefc2630..52b1198c 100644 --- a/tests/linalg/cholesky.rs +++ b/tests/linalg/cholesky.rs @@ -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) + } } } }