2018-02-02 19:26:35 +08:00
|
|
|
use na::{Cholesky, DMatrix, DVector};
|
2017-08-03 01:37:44 +08:00
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_100x100(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 100);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_100x100", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(Cholesky::new(m.clone())))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_500x500(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 500);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_500x500", move |bh| {
|
2021-04-12 16:52:17 +08:00
|
|
|
bh.iter(|| std::hint::black_box(Cholesky::new(m.clone())))
|
2020-04-06 00:49:48 +08:00
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// With unpack.
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_decompose_unpack_100x100(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 100);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_decompose_unpack_100x100", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let chol = Cholesky::new(m.clone()).unwrap();
|
|
|
|
let _ = chol.unpack();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_decompose_unpack_500x500(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 500);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_decompose_unpack_500x500", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let chol = Cholesky::new(m.clone()).unwrap();
|
|
|
|
let _ = chol.unpack();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_solve_10x10(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(10, 10);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
let v = DVector::<f64>::new_random(10);
|
|
|
|
let chol = Cholesky::new(m.clone()).unwrap();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_solve_10x10", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let _ = chol.solve(&v);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_solve_100x100(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 100);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
let v = DVector::<f64>::new_random(100);
|
|
|
|
let chol = Cholesky::new(m.clone()).unwrap();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_solve_100x100", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let _ = chol.solve(&v);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_solve_500x500(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 500);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
let v = DVector::<f64>::new_random(500);
|
|
|
|
let chol = Cholesky::new(m.clone()).unwrap();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_solve_500x500", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let _ = chol.solve(&v);
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_inverse_10x10(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(10, 10);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
let chol = Cholesky::new(m.clone()).unwrap();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_inverse_10x10", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let _ = chol.inverse();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_inverse_100x100(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(100, 100);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
let chol = Cholesky::new(m.clone()).unwrap();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_inverse_100x100", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let _ = chol.inverse();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
|
|
|
|
2019-03-24 02:07:16 +08:00
|
|
|
fn cholesky_inverse_500x500(bh: &mut criterion::Criterion) {
|
2017-08-03 01:37:44 +08:00
|
|
|
let m = DMatrix::<f64>::new_random(500, 500);
|
|
|
|
let m = &m * m.transpose();
|
|
|
|
let chol = Cholesky::new(m.clone()).unwrap();
|
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
bh.bench_function("cholesky_inverse_500x500", move |bh| {
|
|
|
|
bh.iter(|| {
|
|
|
|
let _ = chol.inverse();
|
|
|
|
})
|
|
|
|
});
|
2017-08-03 01:37:44 +08:00
|
|
|
}
|
2019-03-24 02:07:16 +08:00
|
|
|
|
2020-04-06 00:49:48 +08:00
|
|
|
criterion_group!(
|
|
|
|
cholesky,
|
2019-03-24 02:07:16 +08:00
|
|
|
cholesky_100x100,
|
|
|
|
cholesky_500x500,
|
|
|
|
cholesky_decompose_unpack_100x100,
|
|
|
|
cholesky_decompose_unpack_500x500,
|
|
|
|
cholesky_solve_10x10,
|
|
|
|
cholesky_solve_100x100,
|
|
|
|
cholesky_solve_500x500,
|
|
|
|
cholesky_inverse_10x10,
|
|
|
|
cholesky_inverse_100x100,
|
|
|
|
cholesky_inverse_500x500
|
2020-04-06 00:49:48 +08:00
|
|
|
);
|