2021-03-01 00:52:14 +08:00
|
|
|
#![cfg(feature = "proptest-support")]
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
macro_rules! gen_tests(
|
2021-03-01 00:52:14 +08:00
|
|
|
($module: ident, $scalar: expr) => {
|
2019-03-23 18:46:56 +08:00
|
|
|
mod $module {
|
|
|
|
#[allow(unused_imports)]
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::core::helper::{RandScalar, RandComplex};
|
2019-03-23 18:46:56 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
use crate::proptest::*;
|
|
|
|
use proptest::{prop_assert, proptest};
|
2019-03-23 18:46:56 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
proptest! {
|
|
|
|
#[test]
|
|
|
|
fn bidiagonal(m in dmatrix_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let bidiagonal = m.clone().bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn bidiagonal_static_5_3(m in matrix5x3_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let bidiagonal = m.bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn bidiagonal_static_3_5(m in matrix3x5_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let bidiagonal = m.bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn bidiagonal_static_square(m in matrix4_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let bidiagonal = m.bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn bidiagonal_static_square_2x2(m in matrix2_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let bidiagonal = m.bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
}
|
2019-03-23 18:46:56 +08:00
|
|
|
);
|
2019-03-20 05:53:21 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
gen_tests!(complex, complex_f64());
|
|
|
|
gen_tests!(f64, PROPTEST_F64);
|
2019-03-20 05:53:21 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bidiagonal_identity() {
|
2019-03-23 18:46:56 +08:00
|
|
|
let m = na::DMatrix::<f64>::identity(10, 10);
|
2019-03-20 05:53:21 +08:00
|
|
|
let bidiagonal = m.clone().bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
assert_eq!(m, &u * d * &v_t);
|
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
let m = na::DMatrix::<f64>::identity(10, 15);
|
2019-03-20 05:53:21 +08:00
|
|
|
let bidiagonal = m.clone().bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
assert_eq!(m, &u * d * &v_t);
|
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
let m = na::DMatrix::<f64>::identity(15, 10);
|
2019-03-20 05:53:21 +08:00
|
|
|
let bidiagonal = m.clone().bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
assert_eq!(m, &u * d * &v_t);
|
2020-04-06 00:49:48 +08:00
|
|
|
}
|