Skip to content

Commit d9483ea

Browse files
nilgoyetteLukeMathWalker
authored andcommitted
Weighted var (#55)
* Move summary statistic tests outside * Add weighted variance and standard deviation * Add tests * Add axis versions * Add tests for axis versions * ddof expect and doc * Fmt * Add benches
1 parent cb39419 commit d9483ea

File tree

5 files changed

+621
-315
lines changed

5 files changed

+621
-315
lines changed

Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ num-bigint = "0.2.2"
3636
[[bench]]
3737
name = "sort"
3838
harness = false
39+
40+
[[bench]]
41+
name = "summary_statistics"
42+
harness = false

benches/summary_statistics.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use criterion::{
2+
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion,
3+
ParameterizedBenchmark, PlotConfiguration,
4+
};
5+
use ndarray::prelude::*;
6+
use ndarray_rand::RandomExt;
7+
use ndarray_stats::SummaryStatisticsExt;
8+
use rand::distributions::Uniform;
9+
10+
fn weighted_std(c: &mut Criterion) {
11+
let lens = vec![10, 100, 1000, 10000];
12+
let benchmark = ParameterizedBenchmark::new(
13+
"weighted_std",
14+
|bencher, &len| {
15+
let data = Array::random(len, Uniform::new(0.0, 1.0));
16+
let mut weights = Array::random(len, Uniform::new(0.0, 1.0));
17+
weights /= weights.sum();
18+
bencher.iter_batched(
19+
|| data.clone(),
20+
|arr| {
21+
black_box(arr.weighted_std(&weights, 0.0).unwrap());
22+
},
23+
BatchSize::SmallInput,
24+
)
25+
},
26+
lens,
27+
)
28+
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic));
29+
c.bench("weighted_std", benchmark);
30+
}
31+
32+
criterion_group! {
33+
name = benches;
34+
config = Criterion::default();
35+
targets = weighted_std
36+
}
37+
criterion_main!(benches);

0 commit comments

Comments
 (0)