Skip to content

Commit cea3c0e

Browse files
committed
Add benchmarks for truncated eigenvalue decomposition
1 parent f25a177 commit cea3c0e

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ optional = true
5353
paste = "0.1"
5454
criterion = "0.3"
5555

56+
[[bench]]
57+
name = "truncated_eig"
58+
harness = false
59+
5660
[[bench]]
5761
name = "eigh"
5862
harness = false
63+

benches/truncated_eig.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#[macro_use]
2+
extern crate criterion;
3+
4+
use criterion::Criterion;
5+
use ndarray::*;
6+
use ndarray_linalg::*;
7+
8+
macro_rules! impl_teig {
9+
($n:expr) => {
10+
paste::item! {
11+
fn [<teig $n>](c: &mut Criterion) {
12+
c.bench_function(&format!("truncated_eig{}", $n), |b| {
13+
let a: Array2<f64> = random(($n, $n));
14+
let a = a.t().dot(&a);
15+
16+
b.iter(move || {
17+
let _result = TruncatedEig::new(a.clone(), TruncatedOrder::Largest).decompose(1);
18+
})
19+
});
20+
c.bench_function(&format!("truncated_eig{}_t", $n), |b| {
21+
let a: Array2<f64> = random(($n, $n).f());
22+
let a = a.t().dot(&a);
23+
24+
b.iter(|| {
25+
let _result = TruncatedEig::new(a.clone(), TruncatedOrder::Largest).decompose(1);
26+
})
27+
});
28+
}
29+
}
30+
};
31+
}
32+
33+
impl_teig!(4);
34+
impl_teig!(8);
35+
impl_teig!(16);
36+
impl_teig!(32);
37+
impl_teig!(64);
38+
impl_teig!(128);
39+
40+
criterion_group!(teig, teig4, teig8, teig16, teig32, teig64, teig128);
41+
criterion_main!(teig);

0 commit comments

Comments
 (0)