forked from rust-ndarray/ndarray-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
Improve bulk quantiles #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
LukeMathWalker
merged 19 commits into
LukeMathWalker:bulk-quantiles
from
rust-ndarray:bulk-quantiles
Apr 2, 2019
Merged
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7b4e0de
Clarify docs of get_many_from_sorted_mut_unchecked
jturner314 64ed72b
Add get_many_from_sorted_mut benchmark
jturner314 2c90309
Add get_from_sorted_mut benchmark
jturner314 3a4ea2e
Simplify get_many_from_sorted_mut_unchecked
jturner314 e5c9474
Eliminate allocations from _get_many_from_sorted_mut_unchecked
jturner314 24ee710
Call slice_axis_mut instead of slice_mut
jturner314 8739c3b
Replace iter::repeat with vec!
jturner314 88d896f
Fix typo in comment
jturner314 29d507b
Remove unnecessary type annotation
jturner314 d0879c8
Simplify quantiles tests
jturner314 54c11be
Check keys in test_sorted_get_many_mut
jturner314 847fcd5
Simplify sort tests
jturner314 c6f762a
Improve sort and quantiles docs
jturner314 1685095
Make Interpolate::interpolate operate elementwise
jturner314 e965e85
Make quantiles_* return Array instead of IndexMap
jturner314 cfc408f
Add interpolate parameter to quantile*
jturner314 b5d8a08
Make get_many_from_sorted_mut take array of indexes
jturner314 00a21c0
Make quantiles* take array instead of slice
jturner314 8f9f0b6
Remove unnecessary IndexSet
jturner314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
extern crate criterion; | ||
extern crate ndarray; | ||
extern crate ndarray_stats; | ||
extern crate rand; | ||
|
||
use criterion::{ | ||
black_box, criterion_group, criterion_main, AxisScale, BatchSize, Criterion, | ||
ParameterizedBenchmark, PlotConfiguration, | ||
}; | ||
use ndarray::prelude::*; | ||
use ndarray_stats::Sort1dExt; | ||
use rand::prelude::*; | ||
|
||
fn get_from_sorted_mut(c: &mut Criterion) { | ||
let lens = vec![10, 100, 1000, 10000]; | ||
let benchmark = ParameterizedBenchmark::new( | ||
"get_from_sorted_mut", | ||
|bencher, &len| { | ||
let mut rng = StdRng::seed_from_u64(42); | ||
let mut data: Vec<_> = (0..len).collect(); | ||
data.shuffle(&mut rng); | ||
let indices: Vec<_> = (0..len).step_by(len / 10).collect(); | ||
bencher.iter_batched( | ||
|| Array1::from(data.clone()), | ||
|mut arr| { | ||
for &i in &indices { | ||
black_box(arr.get_from_sorted_mut(i)); | ||
} | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}, | ||
lens, | ||
) | ||
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic)); | ||
c.bench("get_from_sorted_mut", benchmark); | ||
} | ||
|
||
fn get_many_from_sorted_mut(c: &mut Criterion) { | ||
let lens = vec![10, 100, 1000, 10000]; | ||
let benchmark = ParameterizedBenchmark::new( | ||
"get_many_from_sorted_mut", | ||
|bencher, &len| { | ||
let mut rng = StdRng::seed_from_u64(42); | ||
let mut data: Vec<_> = (0..len).collect(); | ||
data.shuffle(&mut rng); | ||
let indices: Vec<_> = (0..len).step_by(len / 10).collect(); | ||
bencher.iter_batched( | ||
|| Array1::from(data.clone()), | ||
|mut arr| { | ||
black_box(arr.get_many_from_sorted_mut(&indices)); | ||
}, | ||
BatchSize::SmallInput, | ||
) | ||
}, | ||
lens, | ||
) | ||
.plot_config(PlotConfiguration::default().summary_scale(AxisScale::Logarithmic)); | ||
c.bench("get_many_from_sorted_mut", benchmark); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default(); | ||
targets = get_from_sorted_mut, get_many_from_sorted_mut | ||
} | ||
criterion_main!(benches); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see the rationale for all the changes you have proposed, but I feel I am missing something here: why is
slice_axis_mut
preferable toslice_mut
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just slightly lower overhead, that's all.
.slice_mut()
goes through all the n-dimensional slicing infrastructure and in the end calls.slice_axis_inplace()
;.slice_axis_mut()
jumps there directly. [Edit: In theory, the compiler should be able to eliminate the extra slicing infrastructure through constant propagation and inlining, but in practice, some overhead usually remains.] The performance difference is quite small in this case (~2% in the small array tests when I tried it earlier), so if.slice_mut()
seems cleaner, that's fine too.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Readibility-wise, I'd say they are the same. I was just curious to understand the rationale, your laser-focused optimization eye is something I am trying to learn from your PR reviews 😛