Use proptest for testing the polar decomposition

This commit is contained in:
Sébastien Crozet 2021-12-30 22:15:22 +01:00
parent cc10b67dd1
commit 8e0ca439c2
1 changed files with 19 additions and 29 deletions

View File

@ -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::<f64>::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::<f64>::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);
}