-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Reduction functions with pre-allocated output storage. #6197
Conversation
Inplace reduction functions (including sum!, prod!, maximum!, minimum!, all!, and any!) have been within the Base for a while. This PR exports them with a modified interface that is safe & flexible.
I have to confess I'm a bit confused about what these functions do. Can you add some documentation and/or just post it here? In-place |
It's not really an in-place reduction - I had that thought, too. They just allow you to provide a pre-allocated output buffer, |
Thanks for doing this. Your implementation looks fine to me. We'll need documentation too. Right now I'm too busy with other things to contribute towards that, but if this isn't done in a week or two I can help out. |
Sorry, this is not in-place. They just allow you to write the results to a pre-allocated storage. For example, x = rand(4, 3);
r = zeros(1, 3);
sum!(r, x); # write sum(x, 1) to a pre-allocated r |
I have changed to title to express the meaning more accurately. |
Oh, right – yes, that makes perfect sense. Thanks for doing this. |
I have added the documentation & news entry. Should be ready to merge when it passes travis. |
Reduction functions with pre-allocated output storage.
Inplace reduction functions (including
sum!
,prod!
,maximum!
,minimum!
,all!
, andany!
) have been in the Base for a while (without being exported). This PR exports them with a modified interface that is safe & flexible.The interface is defined as:
The function reduces
A
tor
along dimensions determined by the size ofr
andA
. This behavior has been in the Base before this PR. What I modify is to add aninit
keyword argument, such that wheninit
istrue
(default), it initializesr
properly before doing the reduction, and wheninit
isfalse
, it simply accumulatesA
tor
.A few downstream packages rely on these functions, so that they can do reduction along certain dimensions without allocating new arrays.