From 98e0526bbbe3504657d0014294257395b0daaf28 Mon Sep 17 00:00:00 2001 From: Michael Riss Date: Sat, 14 Nov 2015 01:18:10 +0100 Subject: [PATCH] Provide test case for a diagonal matrix resulting in NaN values from the QR eigenvalue computation. --- tests/mat.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/mat.rs b/tests/mat.rs index 72c14877..efe88538 100644 --- a/tests/mat.rs +++ b/tests/mat.rs @@ -583,6 +583,22 @@ fn test_eigen_qr_mat6() { test_eigen_qr_impl!(Mat6); } +use std::f64; +use na::Iterable; +#[test] +fn test_eigen_qr_diagonal() { + let cov = Mat3::new( 1.0, 0.0, 0.0, + 0.0, 1.0, 0.0, + 0.0, 0.0, 1.0 ); + let (eigvec, eigval) = na::eigen_qr(&cov, &f64::EPSILON, 1000); + for x in eigvec.iter() { + assert!( !x.is_nan(), "NaN values detected, eigvec = {:?}", eigvec ); + } + for x in eigval.iter() { + assert!( !x.is_nan(), "NaN values detected, eigval = {:?}", eigval ); + } +} + #[test] fn test_from_fn() { let actual: DMat = DMat::from_fn(3, 4, |i, j| 10 * i + j);