-
Notifications
You must be signed in to change notification settings - Fork 509
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
Need an unzip()
operator.
#323
Comments
I actually have been thinking about this. The signature of fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
where FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Iterator<Item=(A, B)> To that end, I've started implementing a However, note that I think as a first step, we could implement an |
…on involved. Need to figure out how to get rid of it; see https://github.com/nikomatsakis/rayon/issues/323
You could manually do this with current APIs if you just zip the result vectors in there too, writing with v1.par_iter().zip(&v2)
.zip(r1.par_iter_mut().zip(&mut r2)
.for_each(|((a, b), (x, y))| {
*x = a + b;
*y = a * b;
}); You can generalize this to as large of N as you like. But this does mean you have to initialize the values in the result vectors, or deal with the unsafety of using them uninitialized. |
See #326 for |
I was thinking whether we could support a truly general version of fn unzip_with<F1, R1, F2, R2>(self, left: F1, right: F2) -> (R1, R2)
where F1: Fn(ParallelIterator) -> R1,
F2: Fn(ParallelIterator) -> R2; But you can't really do that, because Anyway, the standard |
Given the existing |
IMO we're done. @icefoxen are you satisfied? |
Yep, totally. Looks good, thanks! |
Essentially, I want to collect N vec's together, map a tuple over them that returns N values, and divide that back up into N vec's, ideally without allocating anything new. Currently, it works quite well for N=1:
What I want to do is something like this:
If there were an
unzip()
I could do something like this maybe:and it would be a little awkward but would generalize to any N (for my use case, N ~ 6 or 8). But if there's a way to do this with the current API I haven't yet figured it out.
The text was updated successfully, but these errors were encountered: