-
Notifications
You must be signed in to change notification settings - Fork 307
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 a par_fold method to Zip to improve the discoverability of Rayon's fold-reduce idiom. #1095
Conversation
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.
Seems good - par equivalent of existing Zip::fold. I don't want us to forward everything from parallel iterators to Zip, so let's be conservative with that. It is written in the docs how to use those methods already.
src/parallel/impl_par_methods.rs
Outdated
/// let a = Array::<usize, _>::ones((128, 1024)); | ||
/// let b = Array::<usize, _>::ones(128); | ||
/// | ||
/// let sum = Zip::from(a.rows()).and(b.view()).par_fold( |
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.
/// let sum = Zip::from(a.rows()).and(b.view()).par_fold( | |
/// let weighted_sum = Zip::from(a.rows()).and(&b).par_fold( |
weighted_sum
is just a suggestion.
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.
You could if you want sync up even more with the existing Zip::fold
in terms of "presentation". By no means necessary, just saying what I'm thinking - (see existing ones to see that they are not perfect). If you want, we mention something like par for each's This is a shorthand for using .into_par_iter().for_each() on Zip.
I do agree which is why I only went for the most common combination of
I do have one question concerning you suggestion though, in let weighted_sum = Zip::from(&a).and(&b).par_fold( you removed the |
Added a suggestion on how this could be worded. I am not too invested in that though as there are too many things to consider in each particular situation so that such general advice might not apply. |
…s fold-reduce idiom.
Oh, I'm sorry about removing the .rows() thing - I was reading way too fast, thought it was .view() too. |
Fixes #1094