Skip to content

Commit 178b302

Browse files
committed
Add tests for matching shape checks in Solve
1 parent 6de9acc commit 178b302

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

ndarray-linalg/tests/solve.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
use ndarray::*;
22
use ndarray_linalg::*;
33

4+
#[should_panic]
5+
#[test]
6+
fn solve_shape_mismatch() {
7+
let a: Array2<f64> = random((3, 3));
8+
let b: Array1<f64> = random(2);
9+
let _ = a.solve_into(b);
10+
}
11+
412
#[test]
513
fn solve_random() {
614
let a: Array2<f64> = random((3, 3));
@@ -10,6 +18,14 @@ fn solve_random() {
1018
assert_close_l2!(&x, &y, 1e-7);
1119
}
1220

21+
#[should_panic]
22+
#[test]
23+
fn solve_t_shape_mismatch() {
24+
let a: Array2<f64> = random((3, 3).f());
25+
let b: Array1<f64> = random(4);
26+
let _ = a.solve_into(b);
27+
}
28+
1329
#[test]
1430
fn solve_random_t() {
1531
let a: Array2<f64> = random((3, 3).f());
@@ -19,6 +35,15 @@ fn solve_random_t() {
1935
assert_close_l2!(&x, &y, 1e-7);
2036
}
2137

38+
#[should_panic]
39+
#[test]
40+
fn solve_factorized_shape_mismatch() {
41+
let a: Array2<f64> = random((3, 3));
42+
let b: Array1<f64> = random(4);
43+
let f = a.factorize_into().unwrap();
44+
let _ = f.solve_into(b);
45+
}
46+
2247
#[test]
2348
fn solve_factorized() {
2449
let a: Array2<f64> = random((3, 3));
@@ -29,6 +54,15 @@ fn solve_factorized() {
2954
assert_close_l2!(&x, &ans, 1e-7);
3055
}
3156

57+
#[should_panic]
58+
#[test]
59+
fn solve_factorized_t_shape_mismatch() {
60+
let a: Array2<f64> = random((3, 3).f());
61+
let b: Array1<f64> = random(4);
62+
let f = a.factorize_into().unwrap();
63+
let _ = f.solve_into(b);
64+
}
65+
3266
#[test]
3367
fn solve_factorized_t() {
3468
let a: Array2<f64> = random((3, 3).f());

0 commit comments

Comments
 (0)