Skip to content

Commit 417c7ad

Browse files
committed
Test for Cholesky
1 parent 3a21b4d commit 417c7ad

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

tests/cholesky.rs

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
include!("header.rs");
22

3-
#[test]
4-
fn cholesky() {
5-
let r_dist = RealNormal::new(0., 1.);
6-
let mut a = Array::<f64, _>::random((3, 3), r_dist);
7-
a = a.dot(&a.t());
8-
println!("a = \n{:?}", a);
9-
let c = a.clone().cholesky().unwrap();
10-
println!("c = \n{:?}", c);
11-
println!("cc = \n{:?}", c.t().dot(&c));
12-
all_close_l2(&c.t().dot(&c), &a, 1e-7).unwrap();
3+
macro_rules! impl_test {
4+
($modname:ident, $clone:ident) => {
5+
mod $modname {
6+
use super::random_hermite;
7+
use ndarray_linalg::prelude::*;
8+
#[test]
9+
fn cholesky() {
10+
let a = random_hermite(3);
11+
println!("a = \n{:?}", a);
12+
let c = a.$clone().cholesky().unwrap();
13+
println!("c = \n{:?}", c);
14+
println!("cc = \n{:?}", c.t().dot(&c));
15+
all_close_l2(&c.t().dot(&c), &a, 1e-7).unwrap();
16+
}
17+
#[test]
18+
fn cholesky_t() {
19+
let a = random_hermite(3);
20+
println!("a = \n{:?}", a);
21+
let c = a.$clone().cholesky().unwrap();
22+
println!("c = \n{:?}", c);
23+
println!("cc = \n{:?}", c.t().dot(&c));
24+
all_close_l2(&c.t().dot(&c), &a, 1e-7).unwrap();
25+
}
1326
}
27+
}} // impl_test
1428

15-
#[test]
16-
fn cholesky_t() {
17-
let r_dist = RealNormal::new(0., 1.);
18-
let mut a = Array::<f64, _>::random((3, 3), r_dist);
19-
a = a.dot(&a.t()).reversed_axes();
20-
println!("a = \n{:?}", a);
21-
let c = a.clone().cholesky().unwrap();
22-
println!("c = \n{:?}", c);
23-
println!("cc = \n{:?}", c.t().dot(&c));
24-
all_close_l2(&c.t().dot(&c), &a, 1e-7).unwrap();
25-
}
29+
impl_test!(owned, clone);
30+
impl_test!(shared, to_shared);

tests/det.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include!("header.rs");
22

3-
macro_rules! impl_test_det {
3+
macro_rules! impl_test{
44
($modname:ident, $clone:ident) => {
55
mod $modname {
66
use super::random_hermite;
@@ -15,7 +15,7 @@ mod $modname {
1515
deth.assert_close(det_eig, 1.0e-7);
1616
}
1717
}
18-
}} // impl_test_det
18+
}} // impl_test
1919

20-
impl_test_det!(owned, clone);
21-
impl_test_det!(shared, to_shared);
20+
impl_test!(owned, clone);
21+
impl_test!(shared, to_shared);

tests/eigh.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
include!("header.rs");
22

3-
macro_rules! impl_test_eigh {
3+
macro_rules! impl_test {
44
($modname:ident, $clone:ident) => {
55
mod $modname {
66
use ndarray::prelude::*;
@@ -27,7 +27,7 @@ mod $modname {
2727
}
2828
}
2929
}
30-
}} // impl_test_eigh
30+
}} // impl_test
3131

32-
impl_test_eigh!(owned, clone);
33-
impl_test_eigh!(shared, to_shared);
32+
impl_test!(owned, clone);
33+
impl_test!(shared, to_shared);

0 commit comments

Comments
 (0)