| 1 |
#![cfg(feature = "proptest-support")] |
| 2 |
|
| 3 |
use na::Matrix2; |
| 4 |
|
| 5 |
#[test] |
| 6 |
fn hessenberg_simple() { |
| 7 |
let m = Matrix2::new(1.0, 0.0, 1.0, 3.0); |
| 8 |
let hess = m.hessenberg(); |
| 9 |
let (p, h) = hess.unpack(); |
| 10 |
assert!(relative_eq!(m, p * h * p.transpose(), epsilon = 1.0e-7)) |
| 11 |
} |
| 12 |
|
| 13 |
macro_rules! gen_tests( |
| 14 |
($module: ident, $scalar: expr, $scalar_type: ty) => { |
| 15 |
mod $module { |
| 16 |
use na::DMatrix; |
| 17 |
#[allow(unused_imports)] |
| 18 |
use crate::core::helper::{RandScalar, RandComplex}; |
| 19 |
|
| 20 |
use crate::proptest::*; |
| 21 |
use proptest::{prop_assert, proptest}; |
| 22 |
|
| 23 |
proptest! { |
| 24 |
#[test] |
| 25 |
fn hessenberg(n in PROPTEST_MATRIX_DIM) { |
| 26 |
let m = DMatrix::<$scalar_type>::new_random(n, n).map(|e| e.0); |
| 27 |
let hess = m.clone().hessenberg(); |
| 28 |
let (p, h) = hess.unpack(); |
| 29 |
prop_assert!(relative_eq!(m, &p * h * p.adjoint(), epsilon = 1.0e-7)) |
| 30 |
} |
| 31 |
|
| 32 |
#[test] |
| 33 |
fn hessenberg_static_mat2(m in matrix2_($scalar)) { |
| 34 |
let hess = m.hessenberg(); |
| 35 |
let (p, h) = hess.unpack(); |
| 36 |
prop_assert!(relative_eq!(m, p * h * p.adjoint(), epsilon = 1.0e-7)) |
| 37 |
} |
| 38 |
|
| 39 |
#[test] |
| 40 |
fn hessenberg_static(m in matrix4_($scalar)) { |
| 41 |
let hess = m.hessenberg(); |
| 42 |
let (p, h) = hess.unpack(); |
| 43 |
prop_assert!(relative_eq!(m, p * h * p.adjoint(), epsilon = 1.0e-7)) |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
); |
| 49 |
|
| 50 |
gen_tests!(complex, complex_f64(), RandComplex<f64>); |
| 51 |
gen_tests!(f64, PROPTEST_F64, RandScalar<f64>); |