2021-03-01 00:52:14 +08:00
|
|
|
#![cfg(feature = "proptest-support")]
|
2018-01-17 23:48:47 +08:00
|
|
|
|
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 {
|
2021-03-01 00:52:14 +08:00
|
|
|
use na::{Matrix4, ComplexField};
|
2019-03-23 18:46:56 +08:00
|
|
|
#[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};
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2019-03-25 18:19:36 +08:00
|
|
|
fn unzero_diagonal<N: ComplexField>(a: &mut Matrix4<N>) {
|
2019-03-23 18:46:56 +08:00
|
|
|
for i in 0..4 {
|
2019-03-23 18:48:12 +08:00
|
|
|
if a[(i, i)].norm1() < na::convert(1.0e-7) {
|
2019-03-23 18:46:56 +08:00
|
|
|
a[(i, i)] = N::one();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
proptest! {
|
|
|
|
#[test]
|
|
|
|
fn solve_lower_triangular(a in matrix4_($scalar), b in matrix4x5_($scalar)) {
|
|
|
|
let mut a = a;
|
2019-03-23 18:46:56 +08:00
|
|
|
unzero_diagonal(&mut a);
|
|
|
|
let tri = a.lower_triangle();
|
|
|
|
let x = a.solve_lower_triangular(&b).unwrap();
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(tri * x, b, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn solve_upper_triangular(a in matrix4_($scalar), b in matrix4x5_($scalar)) {
|
|
|
|
let mut a = a;
|
2019-03-23 18:46:56 +08:00
|
|
|
unzero_diagonal(&mut a);
|
|
|
|
let tri = a.upper_triangle();
|
|
|
|
let x = a.solve_upper_triangular(&b).unwrap();
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(tri * x, b, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn tr_solve_lower_triangular(a in matrix4_($scalar), b in matrix4x5_($scalar)) {
|
|
|
|
let mut a = a;
|
2019-03-23 18:46:56 +08:00
|
|
|
unzero_diagonal(&mut a);
|
|
|
|
let tri = a.lower_triangle();
|
|
|
|
let x = a.tr_solve_lower_triangular(&b).unwrap();
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(tri.transpose() * x, b, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +08:00
|
|
|
}
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
#[test]
|
|
|
|
fn tr_solve_upper_triangular(a in matrix4_($scalar), b in matrix4x5_($scalar)) {
|
|
|
|
let mut a = a;
|
2019-03-23 18:46:56 +08:00
|
|
|
unzero_diagonal(&mut a);
|
|
|
|
let tri = a.upper_triangle();
|
|
|
|
let x = a.tr_solve_upper_triangular(&b).unwrap();
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2021-03-01 00:52:14 +08:00
|
|
|
prop_assert!(relative_eq!(tri.transpose() * x, b, epsilon = 1.0e-7))
|
2019-03-23 18:46:56 +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);
|