2018-01-17 23:48:47 +08:00
|
|
|
use na::{DMatrix, Matrix3, Matrix4};
|
2017-08-03 01:37:44 +08:00
|
|
|
|
|
|
|
#[test]
|
2020-06-07 15:28:39 +08:00
|
|
|
#[rustfmt::skip]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn schur_simpl_mat3() {
|
|
|
|
let m = Matrix3::new(-2.0, -4.0, 2.0,
|
2021-03-01 00:52:14 +08:00
|
|
|
-2.0, 1.0, 2.0,
|
|
|
|
4.0, 2.0, 5.0);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
let schur = m.schur();
|
2017-08-03 01:37:44 +08:00
|
|
|
let (vecs, vals) = schur.unpack();
|
|
|
|
|
|
|
|
assert!(relative_eq!(vecs * vals * vecs.transpose(), m, epsilon = 1.0e-7));
|
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[cfg(feature = "proptest-support")]
|
|
|
|
mod proptest_tests {
|
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};
|
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 schur(m in dmatrix_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let (vecs, vals) = m.clone().schur().unpack();
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(&vecs * vals * vecs.adjoint(), m, epsilon = 1.0e-7));
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn schur_static_mat2(m in matrix2_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let (vecs, vals) = m.clone().schur().unpack();
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(vecs * vals * vecs.adjoint(), m, epsilon = 1.0e-7));
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn schur_static_mat3(m in matrix3_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let (vecs, vals) = m.clone().schur().unpack();
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(vecs * vals * vecs.adjoint(), m, epsilon = 1.0e-7));
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn schur_static_mat4(m in matrix4_($scalar)) {
|
2019-03-23 18:46:56 +08:00
|
|
|
let (vecs, vals) = m.clone().schur().unpack();
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(vecs * vals * vecs.adjoint(), m, epsilon = 1.0e-7));
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
|
|
|
}
|
2018-01-17 23:48:47 +08:00
|
|
|
}
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
2019-03-23 18:46:56 +08:00
|
|
|
);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
gen_tests!(complex, complex_f64());
|
|
|
|
gen_tests!(f64, PROPTEST_F64);
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-06-07 15:28:39 +08:00
|
|
|
#[rustfmt::skip]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn schur_static_mat4_fail() {
|
|
|
|
let m = Matrix4::new(
|
|
|
|
33.32699857679677, 46.794945978960044, -20.792148817005838, 84.73945485997737,
|
|
|
|
-53.04896234480401, -4.031523330630989, 19.022858300892366, -93.2258351951158,
|
|
|
|
-94.61793793643038, -18.64216213611094, 88.32376703241675, -99.30169870309795,
|
|
|
|
90.62661897246733, 96.74200696130146, 34.7421322611369, 84.86773307198098);
|
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
let (vecs, vals) = m.clone().schur().unpack();
|
2017-08-03 01:37:44 +08:00
|
|
|
assert!(relative_eq!(vecs * vals * vecs.transpose(), m, epsilon = 1.0e-7))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-06-07 15:28:39 +08:00
|
|
|
#[rustfmt::skip]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn schur_static_mat4_fail2() {
|
|
|
|
let m = Matrix4::new(
|
|
|
|
14.623586538485966, 7.646156622760756, -52.11923331576265, -97.50030223503413,
|
|
|
|
53.829398131426785, -33.40560799661168, 70.31168286972388, -81.25248138434173,
|
|
|
|
27.932377940728202, 82.94220150938, -35.5898884705951, 67.56447552434219,
|
|
|
|
55.66754906908682, -42.14328890569226, -20.684709585152206, -87.9456949841046);
|
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
let (vecs, vals) = m.clone().schur().unpack();
|
2017-08-03 01:37:44 +08:00
|
|
|
assert!(relative_eq!(vecs * vals * vecs.transpose(), m, epsilon = 1.0e-7))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-06-07 15:28:39 +08:00
|
|
|
#[rustfmt::skip]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn schur_static_mat3_fail() {
|
|
|
|
let m = Matrix3::new(
|
|
|
|
-21.58457553143394, -67.3881542667948, -14.619829849784338,
|
|
|
|
-7.525423104386547, -17.827350599642287, 11.297377444555849,
|
|
|
|
38.080736654870464, -84.27428302131528, -95.88198590331922);
|
|
|
|
|
2019-03-23 18:46:56 +08:00
|
|
|
let (vecs, vals) = m.clone().schur().unpack();
|
2017-08-03 01:37:44 +08:00
|
|
|
assert!(relative_eq!(vecs * vals * vecs.transpose(), m, epsilon = 1.0e-7))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test proposed on the issue #176 of rulinalg.
|
|
|
|
#[test]
|
2020-06-07 15:28:39 +08:00
|
|
|
#[rustfmt::skip]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn schur_singular() {
|
|
|
|
let m = DMatrix::from_row_slice(24, 24, &[
|
|
|
|
1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
|
|
|
-1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0,
|
|
|
|
0.0, -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
|
|
|
|
0.0, 0.0, -4.0, 0.0, 0.0, 0.0, 0.0, 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