From ab0d335b61f9869d8a958c7ac84ea80ecba8d42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crozet=20S=C3=A9bastien?= Date: Thu, 25 Feb 2021 13:16:04 +0100 Subject: [PATCH] Fix tests for the UDU decomposition. --- src/linalg/udu.rs | 9 ++++++--- tests/linalg/udu.rs | 21 +++++++-------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/linalg/udu.rs b/src/linalg/udu.rs index 46b1497c..346753b2 100644 --- a/src/linalg/udu.rs +++ b/src/linalg/udu.rs @@ -7,7 +7,7 @@ use crate::dimension::Dim; use crate::storage::Storage; use simba::scalar::RealField; -/// UDU factorization +/// UDU factorization. #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", @@ -42,8 +42,11 @@ impl UDU where DefaultAllocator: Allocator + Allocator, { - /// Computes the UDU^T factorization - /// The input matrix `p` is assumed to be symmetric and this decomposition will only read the upper-triangular part of `p`. + /// Computes the UDU^T factorization. + /// + /// The input matrix `p` is assumed to be symmetric and this decomposition will only read + /// the upper-triangular part of `p`. + /// /// Ref.: "Optimal control and estimation-Dover Publications", Robert F. Stengel, (1994) page 360 pub fn new(p: MatrixN) -> Self { let n = p.ncols(); diff --git a/tests/linalg/udu.rs b/tests/linalg/udu.rs index c7f416d7..95cdc9c2 100644 --- a/tests/linalg/udu.rs +++ b/tests/linalg/udu.rs @@ -1,5 +1,4 @@ -use na::Matrix3; -use na::UDU; +use na::{Matrix3, UDU}; #[test] #[rustfmt::skip] @@ -40,19 +39,14 @@ mod quickcheck_tests { macro_rules! gen_tests( ($module: ident, $scalar: ty) => { mod $module { - use std::cmp; - use na::{DMatrix, Matrix4}; + use na::{UDU, DMatrix, Matrix4}; #[allow(unused_imports)] use crate::core::helper::{RandScalar, RandComplex}; quickcheck! { - fn udu(m: DMatrix<$scalar>) -> bool { - let mut m = m; - if m.len() == 0 { - m = DMatrix::<$scalar>::new_random(1, 1); - } - - let m = m.map(|e| e.0); + fn udu(n: usize) -> bool { + let n = std::cmp::max(1, std::cmp::min(n, 10)); + let m = DMatrix::<$scalar>::new_random(n, n).map(|e| e.0).hermitian_part(); let udu = UDU::new(m.clone()); let p = &udu.u * &udu.d_matrix() * &udu.u.transpose(); @@ -61,18 +55,17 @@ mod quickcheck_tests { } fn udu_static(m: Matrix4<$scalar>) -> bool { - let m = m.map(|e| e.0); + let m = m.map(|e| e.0).hermitian_part(); let udu = UDU::new(m.clone()); let p = udu.u * udu.d_matrix() * udu.u.transpose(); - relative_eq!(m, p, epsilon = 3.0e-16) + relative_eq!(m, p, epsilon = 1.0e-7) } } } } ); - gen_tests!(complex, RandComplex); gen_tests!(f64, RandScalar); }