-
Notifications
You must be signed in to change notification settings - Fork 310
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
Add lane sampling to ndarray-rand #724
Add lane sampling to ndarray-rand #724
Conversation
Relaxing the Copy bound on select is a bigger task, I think I'd like to help (but feel free to work on it if you get to it). I consider it a bigger task, since it entails handling copying partial arrays and being able to tear down and drop the partial array if something panics during this operation. Definitely something it's about time to handle. The choice to use Copy to implement something that's fast and safe was a good one at the time. |
Fwiw, The key idea is to collect the data into a use ndarray::prelude::*;
use ndarray::RemoveAxis;
fn select<A, D>(arr: ArrayView<'_, A, D>, axis: Axis, indices: &[usize]) -> Array<A, D>
where
A: Clone,
D: Dimension + RemoveAxis,
{
let data = indices
.iter()
.flat_map(|&index| arr.index_axis(axis, index).iter())
.cloned()
.collect();
// TODO: Check that new length doesn't overflow `isize`.
let mut dim = arr.raw_dim();
dim[axis.index()] = indices.len();
// TODO: Compute strides. `axis` is the outermost axis (largest stride),
// and the remaining axes are in standard order.
let strides = unimplemented!();
Array::from_vec_dim_stride_unchecked(dim, strides, data)
} |
I'll keep this mind, I was planning to have a look this weekend most likely. |
Sorry for the unstructured critique, but how do we decide if it's best with separate methods for independent sampling and sampling with replacement, or to have them in one? Looks like a logical addition anyhow. |
I don't have a strong preference in either direction. |
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.
Regarding the "with/without replacement" question --
It's worth noting that there is a similar method in rand
: SliceRandom::choose_multiple
. It might be beneficial to use similar naming (axis_choose_multiple
, for example). If we did that, we'd want to match the behavior of rand
(samping without replacement) and add a separate method for sampling with replacement (although I'm not sure what we'd call it).
If we handle "with/without replacement" as a parameter, IMO we should make that parameter an enum
instead of a bool
for additional clarity, e.g.
enum Choose {
WithReplacement,
WithoutReplacement,
}
I lean towards a single method with a parameter - I changed it from a I have added a |
I am planning to start working on another convenience function for What is missing for this PR to be merged? Should I branch from here or should I branch from master? Just conscious of wasting time in merge conflicts 😅 |
This needs rebase/fixup :) Otherwise it looks good — I won't have much opinions on ndarray-rand. So I'd say, branch off from this branch, but not in the state it is now. quickcheck as a public dependency is not something I'd like to have for ndarray. |
Add `quickcheck` feature flag to `ndarray-rand` to get `Arbitrary` implementation for `ndarray-rand` types. Update quickcheck dependency in ndarray. Fix CI scripts to run ndarray-rand's tests.
0583689
to
0c9a2e3
Compare
I was going for a squash and merge, but rebasing sounds good as well :)
Could you elaborate? |
I can't elaborate all the way, but if we had quickcheck as a pub dep, then rand is a pub dep of ndarray, and ndarray-rand would be pointless, because the separation would be gone. And sure, we have talked about rand as pub dep as a possibility through dependency rename. Another facet is that serde is 1.0 and has been for a while, and it's a more important feature and a feature that doesn't have alternatives. |
While working on rust-ndarray/ndarray-examples#2 I realised that a sampling method could actually fit quite nicely in
ndarray-rand
.I'd like to relax the
Copy
bound onA
, I need to look deeper intoselect
's implementation.