From 8e0ca439c2431c2e713e8355419a88e2d724f473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Thu, 30 Dec 2021 22:15:22 +0100 Subject: [PATCH] Use proptest for testing the polar decomposition --- tests/linalg/svd.rs | 48 ++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/tests/linalg/svd.rs b/tests/linalg/svd.rs index 13c54a8b..0e725f8e 100644 --- a/tests/linalg/svd.rs +++ b/tests/linalg/svd.rs @@ -153,6 +153,25 @@ mod proptest_tests { prop_assert!(relative_eq!(&m * &sol2, b2, epsilon = 1.0e-6)); } } + + #[test] + fn svd_polar_decomposition(m in dmatrix_($scalar)) { + let svd = m.clone().svd(true, true); + let (p, u) = svd.to_polar().unwrap(); + + assert_relative_eq!(m, &p* &u, epsilon = 1.0e-5); + // semi-unitary check + assert_eq!(true, (u.is_orthogonal(1.0e-5))); + // hermitian check + assert_relative_eq!(p, p.adjoint(), epsilon = 1.0e-5); + + /* + * Same thing, but using the method instead of calling the SVD explicitly. + */ + let (p2, u2) = m.clone().polar(); + assert_eq!(p, p2); + assert_eq!(u, u2); + } } } } @@ -441,32 +460,3 @@ fn svd_sorted() { epsilon = 1.0e-5 ); } - -#[test] -fn dynamic_square_matrix_polar_decomposition() { - - let m = DMatrix::::new_random(10, 10); - let svd = m.clone().svd(true, true); - let (p,u) = svd.to_polar().unwrap(); - - assert_relative_eq!(m, &p*&u, epsilon = 1.0e-5); - // unitary check - assert_eq!(true, u.is_orthogonal(1.0e-5)); - // hermitian check - assert_relative_eq!(p, p.adjoint(), epsilon = 1.0e-5); - -} - -#[test] -fn dynamic_rectangular_matrix_polar_decomposition() { - - let m = DMatrix::::new_random(7, 5); - let svd = m.clone().svd(true, true); - let (p,u) = svd.to_polar().unwrap(); - - assert_relative_eq!(m, &p*&u, epsilon = 1.0e-5); - // semi-unitary check - assert_eq!(true, (u.is_orthogonal(1.0e-5))); - // hermitian check - assert_relative_eq!(p, p.adjoint(), epsilon = 1.0e-5); -}