2022-02-12 15:27:29 +08:00
|
|
|
use na::dimension::Const;
|
|
|
|
use na::{DMatrix, OMatrix};
|
2022-02-12 15:37:26 +08:00
|
|
|
use nl::GeneralizedEigen;
|
2022-01-25 12:56:44 +08:00
|
|
|
use num_complex::Complex;
|
|
|
|
use simba::scalar::ComplexField;
|
|
|
|
|
|
|
|
use crate::proptest::*;
|
2022-02-12 15:27:29 +08:00
|
|
|
use proptest::{prop_assert, prop_compose, proptest};
|
|
|
|
|
|
|
|
prop_compose! {
|
|
|
|
fn f64_squares() (n in PROPTEST_MATRIX_DIM) (a in matrix(PROPTEST_F64,n,n), b in matrix(PROPTEST_F64,n,n)) -> (DMatrix<f64>, DMatrix<f64>){
|
|
|
|
(a,b)
|
|
|
|
}}
|
2022-01-25 12:56:44 +08:00
|
|
|
|
|
|
|
proptest! {
|
|
|
|
#[test]
|
2022-02-12 15:27:29 +08:00
|
|
|
fn ge((a,b) in f64_squares()){
|
|
|
|
|
|
|
|
let a_c = a.clone().map(|x| Complex::new(x, 0.0));
|
|
|
|
let b_c = b.clone().map(|x| Complex::new(x, 0.0));
|
|
|
|
let n = a.shape_generic().0;
|
2022-01-25 12:56:44 +08:00
|
|
|
|
2022-02-12 15:37:26 +08:00
|
|
|
let ge = GeneralizedEigen::new(a.clone(), b.clone());
|
2022-02-12 15:27:29 +08:00
|
|
|
let (vsl,vsr) = ge.clone().eigenvectors();
|
2022-01-25 12:56:44 +08:00
|
|
|
|
|
|
|
|
2022-02-12 15:27:29 +08:00
|
|
|
for (i,(alpha,beta)) in ge.raw_eigenvalues().iter().enumerate() {
|
|
|
|
let l_a = a_c.clone() * Complex::new(*beta, 0.0);
|
|
|
|
let l_b = b_c.clone() * *alpha;
|
2022-01-25 12:56:44 +08:00
|
|
|
|
2022-02-12 15:27:29 +08:00
|
|
|
prop_assert!(
|
|
|
|
relative_eq!(
|
|
|
|
((&l_a - &l_b)*vsr.column(i)).map(|x| x.modulus()),
|
|
|
|
OMatrix::zeros_generic(n, Const::<1>),
|
|
|
|
epsilon = 1.0e-5));
|
2022-02-03 19:36:10 +08:00
|
|
|
|
2022-02-12 15:27:29 +08:00
|
|
|
prop_assert!(
|
|
|
|
relative_eq!(
|
|
|
|
(vsl.column(i).adjoint()*(&l_a - &l_b)).map(|x| x.modulus()),
|
|
|
|
OMatrix::zeros_generic(Const::<1>, n),
|
|
|
|
epsilon = 1.0e-5))
|
2022-01-25 12:56:44 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ge_static(a in matrix4(), b in matrix4()) {
|
|
|
|
|
2022-02-12 15:37:26 +08:00
|
|
|
let ge = GeneralizedEigen::new(a.clone(), b.clone());
|
2022-02-12 15:27:29 +08:00
|
|
|
let a_c =a.clone().map(|x| Complex::new(x, 0.0));
|
|
|
|
let b_c = b.clone().map(|x| Complex::new(x, 0.0));
|
|
|
|
let (vsl,vsr) = ge.eigenvectors();
|
|
|
|
let eigenvalues = ge.raw_eigenvalues();
|
2022-01-25 12:56:44 +08:00
|
|
|
|
2022-02-12 15:27:29 +08:00
|
|
|
for (i,(alpha,beta)) in eigenvalues.iter().enumerate() {
|
|
|
|
let l_a = a_c.clone() * Complex::new(*beta, 0.0);
|
|
|
|
let l_b = b_c.clone() * *alpha;
|
2022-01-25 12:56:44 +08:00
|
|
|
|
2022-02-12 15:27:29 +08:00
|
|
|
prop_assert!(
|
|
|
|
relative_eq!(
|
|
|
|
((&l_a - &l_b)*vsr.column(i)).map(|x| x.modulus()),
|
|
|
|
OMatrix::zeros_generic(Const::<4>, Const::<1>),
|
|
|
|
epsilon = 1.0e-5));
|
|
|
|
prop_assert!(
|
|
|
|
relative_eq!((vsl.column(i).adjoint()*(&l_a - &l_b)).map(|x| x.modulus()),
|
|
|
|
OMatrix::zeros_generic(Const::<1>, Const::<4>),
|
|
|
|
epsilon = 1.0e-5))
|
|
|
|
}
|
2022-01-25 12:56:44 +08:00
|
|
|
}
|
2022-02-12 15:27:29 +08:00
|
|
|
|
2022-01-25 12:56:44 +08:00
|
|
|
}
|