Skip to content

Commit 959d5ac

Browse files
committed
Add test for 2d SolveTriangular
1 parent 3a6f750 commit 959d5ac

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

tests/triangular.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,58 @@ mod $modname {
6363

6464
impl_test!(owned, Array<f64, _>::random);
6565
impl_test!(shared, RcArray<f64, _>::random);
66+
67+
macro_rules! impl_test_2d {
68+
($modname:ident, $drop:path, $solve:ident) => {
69+
mod $modname {
70+
use super::random_owned;
71+
use ndarray_linalg::prelude::*;
72+
#[test]
73+
fn solve_tt() {
74+
let a = $drop(random_owned(3, 3, true));
75+
println!("a = \n{:?}", &a);
76+
let b = random_owned(3, 2, true);
77+
println!("b = \n{:?}", &b);
78+
let x = a.$solve(&b).unwrap();
79+
println!("x = \n{:?}", &x);
80+
println!("Ax = \n{:?}", a.dot(&x));
81+
all_close_l2(&a.dot(&x), &b, 1e-7).unwrap();
82+
}
83+
#[test]
84+
fn solve_tf() {
85+
let a = $drop(random_owned(3, 3, true));
86+
println!("a = \n{:?}", &a);
87+
let b = random_owned(3, 2, false);
88+
println!("b = \n{:?}", &b);
89+
let x = a.$solve(&b).unwrap();
90+
println!("x = \n{:?}", &x);
91+
println!("Ax = \n{:?}", a.dot(&x));
92+
all_close_l2(&a.dot(&x), &b, 1e-7).unwrap();
93+
}
94+
#[test]
95+
fn solve_ft() {
96+
let a = $drop(random_owned(3, 3, false));
97+
println!("a = \n{:?}", &a);
98+
let b = random_owned(3, 2, true);
99+
println!("b = \n{:?}", &b);
100+
let x = a.$solve(&b).unwrap();
101+
println!("x = \n{:?}", &x);
102+
println!("Ax = \n{:?}", a.dot(&x));
103+
all_close_l2(&a.dot(&x), &b, 1e-7).unwrap();
104+
}
105+
#[test]
106+
fn solve_ff() {
107+
let a = $drop(random_owned(3, 3, false));
108+
println!("a = \n{:?}", &a);
109+
let b = random_owned(3, 2, false);
110+
println!("b = \n{:?}", &b);
111+
let x = a.$solve(&b).unwrap();
112+
println!("x = \n{:?}", &x);
113+
println!("Ax = \n{:?}", a.dot(&x));
114+
all_close_l2(&a.dot(&x), &b, 1e-7).unwrap();
115+
}
116+
}
117+
}} // impl_test_2d
118+
119+
impl_test_2d!(lower2d, drop_upper, solve_lower);
120+
impl_test_2d!(upper2d, drop_lower, solve_upper);

0 commit comments

Comments
 (0)