JuliaLang/julia — pull request #6197 by lindahua (2014-03-18 17:18:43+00:00)
Title: Inplace reduction functions

Inplace reduction functions (including ``sum!``, ``prod!``, ``maximum!``, ``minimum!``, ``all!``, and ``any!``) 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:
```julia
sum!(r, A[; init=true])
```
The function reduces ``A`` to ``r`` along dimensions determined by the size of ``r`` and ``A``. This behavior has been in the Base before this PR. What I modify is to add an ``init`` keyword argument, such that when ``init`` is ``true`` (default), it initializes ``r`` properly before doing the reduction, and when ``init`` is ``false``, it simply accumulates ``A`` to ``r``.

A few downstream packages rely on these functions, so that they can do reduction along certain dimensions without allocating new arrays.