2018-01-17 23:48:47 +08:00
|
|
|
#![cfg(feature = "arbitrary")]
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2018-10-22 13:00:10 +08:00
|
|
|
use na::{DMatrix, Matrix2, Matrix3x5, Matrix4, Matrix5x3};
|
2019-03-03 02:33:49 +08:00
|
|
|
use core::helper::{RandScalar, RandComplex};
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2019-03-20 05:53:21 +08:00
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
quickcheck! {
|
2019-03-03 02:33:49 +08:00
|
|
|
fn bidiagonal(m: DMatrix<RandComplex<f64>>) -> bool {
|
|
|
|
let m = m.map(|e| e.0);
|
2017-08-03 01:37:44 +08:00
|
|
|
if m.len() == 0 {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-14 01:52:46 +08:00
|
|
|
let bidiagonal = m.clone().bidiagonalize();
|
2017-08-03 01:37:44 +08:00
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
|
|
|
println!("{}{}{}", &u, &d, &v_t);
|
|
|
|
println!("{:.7}{:.7}", &u * &d * &v_t, m);
|
|
|
|
|
|
|
|
relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
|
2019-03-03 02:33:49 +08:00
|
|
|
fn bidiagonal_static_5_3(m: Matrix5x3<RandComplex<f64>>) -> bool {
|
|
|
|
let m = m.map(|e| e.0);
|
2017-08-14 01:52:46 +08:00
|
|
|
let bidiagonal = m.bidiagonalize();
|
2017-08-03 01:37:44 +08:00
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
|
|
|
println!("{}{}{}", &u, &d, &v_t);
|
|
|
|
println!("{:.7}{:.7}", &u * &d * &v_t, m);
|
|
|
|
|
|
|
|
relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
|
2019-03-03 02:33:49 +08:00
|
|
|
fn bidiagonal_static_3_5(m: Matrix3x5<RandComplex<f64>>) -> bool {
|
|
|
|
let m = m.map(|e| e.0);
|
2017-08-14 01:52:46 +08:00
|
|
|
let bidiagonal = m.bidiagonalize();
|
2017-08-03 01:37:44 +08:00
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
|
|
|
println!("{}{}{}", &u, &d, &v_t);
|
|
|
|
println!("{:.7}{:.7}", &u * &d * &v_t, m);
|
|
|
|
|
|
|
|
relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
|
2019-03-03 02:33:49 +08:00
|
|
|
fn bidiagonal_static_square(m: Matrix4<RandComplex<f64>>) -> bool {
|
|
|
|
let m = m.map(|e| e.0);
|
2017-08-14 01:52:46 +08:00
|
|
|
let bidiagonal = m.bidiagonalize();
|
2017-08-03 01:37:44 +08:00
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
|
|
|
println!("{}{}{}", &u, &d, &v_t);
|
|
|
|
println!("{:.7}{:.7}", &u * &d * &v_t, m);
|
|
|
|
|
|
|
|
relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
|
2019-03-03 02:33:49 +08:00
|
|
|
fn bidiagonal_static_square_2x2(m: Matrix2<RandComplex<f64>>) -> bool {
|
|
|
|
let m = m.map(|e| e.0);
|
2017-08-14 01:52:46 +08:00
|
|
|
let bidiagonal = m.bidiagonalize();
|
2017-08-03 01:37:44 +08:00
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
|
|
|
|
println!("{}{}{}", &u, &d, &v_t);
|
|
|
|
println!("{:.7}{:.7}", &u * &d * &v_t, m);
|
|
|
|
|
|
|
|
relative_eq!(m, &u * d * &v_t, epsilon = 1.0e-7)
|
|
|
|
}
|
|
|
|
}
|
2019-03-20 05:53:21 +08:00
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn bidiagonal_identity() {
|
|
|
|
let m = DMatrix::<f64>::identity(10, 10);
|
|
|
|
let bidiagonal = m.clone().bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
println!("u, s, v_t: {}{}{}", u, d, v_t);
|
|
|
|
println!("recomp: {}", &u * &d * &v_t);
|
|
|
|
assert_eq!(m, &u * d * &v_t);
|
|
|
|
|
|
|
|
let m = DMatrix::<f64>::identity(10, 15);
|
|
|
|
let bidiagonal = m.clone().bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
println!("u, s, v_t: {}{}{}", u, d, v_t);
|
|
|
|
assert_eq!(m, &u * d * &v_t);
|
|
|
|
|
|
|
|
let m = DMatrix::<f64>::identity(15, 10);
|
|
|
|
let bidiagonal = m.clone().bidiagonalize();
|
|
|
|
let (u, d, v_t) = bidiagonal.unpack();
|
|
|
|
println!("u, s, v_t: {}{}{}", u, d, v_t);
|
|
|
|
assert_eq!(m, &u * d * &v_t);
|
|
|
|
}
|