2018-01-17 23:48:47 +08:00
|
|
|
#![cfg(feature = "arbitrary")]
|
|
|
|
|
2017-08-14 01:52:46 +08:00
|
|
|
use na::{DMatrix, Matrix2, Matrix4};
|
2019-03-03 02:33:49 +08:00
|
|
|
use core::helper::{RandScalar, RandComplex};
|
2018-10-22 13:00:10 +08:00
|
|
|
use std::cmp;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2019-03-12 20:15:02 +08:00
|
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
|
|
|
quickcheck! {
|
|
|
|
fn hessenberg(n: usize) -> bool {
|
|
|
|
let n = cmp::max(1, cmp::min(n, 50));
|
2019-03-03 02:33:49 +08:00
|
|
|
let m = DMatrix::<RandComplex<f64>>::new_random(n, n).map(|e| e.0);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2017-08-14 01:52:46 +08:00
|
|
|
let hess = m.clone().hessenberg();
|
2017-08-03 01:37:44 +08:00
|
|
|
let (p, h) = hess.unpack();
|
2019-03-12 20:15:02 +08:00
|
|
|
relative_eq!(m, &p * h * p.conjugate_transpose(), epsilon = 1.0e-7)
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 02:33:49 +08:00
|
|
|
fn hessenberg_static_mat2(m: Matrix2<RandComplex<f64>>) -> bool {
|
|
|
|
let m = m.map(|e| e.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();
|
2019-03-12 20:15:02 +08:00
|
|
|
relative_eq!(m, p * h * p.conjugate_transpose(), epsilon = 1.0e-7)
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-03 02:33:49 +08:00
|
|
|
fn hessenberg_static(m: Matrix4<RandComplex<f64>>) -> bool {
|
|
|
|
let m = m.map(|e| e.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();
|
2019-03-12 20:15:02 +08:00
|
|
|
relative_eq!(m, p * h * p.conjugate_transpose(), epsilon = 1.0e-7)
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
}
|