2021-03-01 00:52:14 +08:00
|
|
|
#![cfg(feature = "proptest-support")]
|
2018-01-17 23:48:47 +08:00
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
use na::Matrix2;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hessenberg_simple() {
|
2018-10-22 13:00:10 +08:00
|
|
|
let m = Matrix2::new(1.0, 0.0, 1.0, 3.0);
|
2017-08-14 01:52:46 +08:00
|
|
|
let hess = m.hessenberg();
|
2017-08-03 01:37:44 +08:00
|
|
|
let (p, h) = hess.unpack();
|
|
|
|
assert!(relative_eq!(m, p * h * p.transpose(), epsilon = 1.0e-7))
|
|
|
|
}
|
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
macro_rules! gen_tests(
|
2021-03-01 17:02:45 +08:00
|
|
|
($module: ident, $scalar: expr, $scalar_type: ty) => {
|
2019-03-23 18:46:56 +08:00
|
|
|
mod $module {
|
2021-03-01 17:02:45 +08:00
|
|
|
use na::DMatrix;
|
2019-03-23 18:46:56 +08:00
|
|
|
#[allow(unused_imports)]
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::core::helper::{RandScalar, RandComplex};
|
2017-08-03 01:37:44 +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]
|
2021-03-01 17:02:45 +08:00
|
|
|
fn hessenberg(n in PROPTEST_MATRIX_DIM) {
|
|
|
|
let m = DMatrix::<$scalar_type>::new_random(n, n).map(|e| e.0);
|
2019-03-23 18:46:56 +08:00
|
|
|
let hess = m.clone().hessenberg();
|
|
|
|
let (p, h) = hess.unpack();
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(m, &p * h * p.adjoint(), epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn hessenberg_static_mat2(m in matrix2_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let hess = m.hessenberg();
|
|
|
|
let (p, h) = hess.unpack();
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(m, p * h * p.adjoint(), epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn hessenberg_static(m in matrix4_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let hess = m.hessenberg();
|
|
|
|
let (p, h) = hess.unpack();
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(m, p * h * p.adjoint(), 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
|
|
|
);
|
|
|
|
|
2021-03-01 17:02:45 +08:00
|
|
|
gen_tests!(complex, complex_f64(), RandComplex<f64>);
|
|
|
|
gen_tests!(f64, PROPTEST_F64, RandScalar<f64>);
|