From bdccc81874b2b26646428a4ce3785dc511e382fb Mon Sep 17 00:00:00 2001 From: Nestor Demeure Date: Sat, 2 Nov 2019 15:56:59 +0100 Subject: [PATCH] got test to compile --- src/linalg/cholesky.rs | 2 +- tests/linalg/cholesky.rs | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/linalg/cholesky.rs b/src/linalg/cholesky.rs index 606434e9..6a2c9da8 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -151,7 +151,7 @@ where /// TODO rewrite comment (current version is taken verbatim from eigen) /// TODO insures that code is correct for complex numbers, eigen uses abs2 and conj /// https://eigen.tuxfamily.org/dox/LLT_8h_source.html - pub fn rank_one_update(&mut self, x: &Matrix, sigma: N) + pub fn rank_one_update(&mut self, x: &Matrix, sigma: N) where S2: Storage, DefaultAllocator: Allocator, diff --git a/tests/linalg/cholesky.rs b/tests/linalg/cholesky.rs index 52b1198c..80a54e2f 100644 --- a/tests/linalg/cholesky.rs +++ b/tests/linalg/cholesky.rs @@ -79,19 +79,22 @@ macro_rules! gen_tests( } fn cholesky_rank_one_update(_n: usize) -> bool { - let m = RandomSDP::new(U4, || random::<$scalar>().0).unwrap(); + let mut m = RandomSDP::new(U4, || random::<$scalar>().0).unwrap(); let x = Vector4::<$scalar>::new_random().map(|e| e.0); - let sigma : $scalar = 1.; + let sigma = random::<$scalar>().0; // random::<$scalar>().0; + let one = sigma*0. + 1.; // TODO this is dirty but $scalar appears to not be a scalar type + + // updates cholesky decomposition and reconstructs m + let mut chol = m.clone().cholesky().unwrap(); + chol.rank_one_update(&x, sigma); + let m_chol_updated = chol.l() * chol.l().adjoint(); // updates m manually - let m_updated = m + sigma * x * x.transpose(); + m.syger(sigma, &x, &x, one); // m += sigma * x * x.adjoint() - // 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(); + println!("m : {:?}", m); - relative_eq!(m_updated, m_chol_updated, epsilon = 1.0e-7) + relative_eq!(m, m_chol_updated, epsilon = 1.0e-7) } } }