Skip to content

Commit cf4adff

Browse files
committed
Add test for deth
1 parent 68d95e3 commit cf4adff

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ features = ["blas"]
2020
[dev-dependencies]
2121
rand = "0.3.14"
2222
ndarray-rand = "0.3"
23+
float-cmp = "0.2.3"

tests/det.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
extern crate ndarray;
3+
extern crate ndarray_linalg;
4+
extern crate ndarray_rand;
5+
extern crate rand;
6+
extern crate float_cmp;
7+
8+
use ndarray::prelude::*;
9+
use ndarray_linalg::prelude::*;
10+
use rand::distributions::*;
11+
use ndarray_rand::RandomExt;
12+
use float_cmp::ApproxEqRatio;
13+
14+
fn approx_eq(val: f64, truth: f64, ratio: f64) {
15+
if !val.approx_eq_ratio(&truth, ratio) {
16+
panic!("Not almost equal! val={:?}, truth={:?}, ratio={:?}",
17+
val,
18+
truth,
19+
ratio);
20+
}
21+
}
22+
23+
fn random_hermite(n: usize) -> Array<f64, Ix2> {
24+
let r_dist = Range::new(0., 1.);
25+
let a = Array::<f64, _>::random((n, n), r_dist);
26+
a.dot(&a.t())
27+
}
28+
29+
#[test]
30+
fn deth() {
31+
let a = random_hermite(3);
32+
let (e, _) = a.clone().eigh().unwrap();
33+
let deth = a.clone().deth().unwrap();
34+
let det_eig = e.iter().fold(1.0, |x, y| x * y);
35+
approx_eq(deth, det_eig, 1.0e-7);
36+
}

0 commit comments

Comments
 (0)