summaryrefslogtreecommitdiff
path: root/numpy/core/src
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-04-12 16:55:21 -0600
committerGitHub <noreply@github.com>2018-04-12 16:55:21 -0600
commit3ec88758813678aadedc58dbfd89646b05001a91 (patch)
tree2368a01839d9d06fcd68da20d8e8033c4f9047cb /numpy/core/src
parent265983b4ec859ad528623f3c5da7c96f83526f4f (diff)
parent1f981eddb7108ac18a7eabfa5ad9cfaecd247b13 (diff)
downloadnumpy-3ec88758813678aadedc58dbfd89646b05001a91.tar.gz
Merge pull request #10665 from pv/accumulate-same-nocopy
ENH: umath: don't make temporary copies for in-place accumulation
Diffstat (limited to 'numpy/core/src')
-rw-r--r--numpy/core/src/umath/ufunc_object.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index bf5a4ead3..6dd597b3a 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -3215,9 +3215,15 @@ PyUFunc_Accumulate(PyUFuncObject *ufunc, PyArrayObject *arr, PyArrayObject *out,
*/
ndim_iter = ndim;
flags |= NPY_ITER_MULTI_INDEX;
- /* Add some more flags */
- op_flags[0] |= NPY_ITER_UPDATEIFCOPY|NPY_ITER_ALIGNED;
- op_flags[1] |= NPY_ITER_COPY|NPY_ITER_ALIGNED;
+ /*
+ * Add some more flags.
+ *
+ * The accumulation outer loop is 'elementwise' over the array, so turn
+ * on NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE. That is, in-place
+ * accumulate(x, out=x) is safe to do without temporary copies.
+ */
+ op_flags[0] |= NPY_ITER_UPDATEIFCOPY|NPY_ITER_ALIGNED|NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
+ op_flags[1] |= NPY_ITER_COPY|NPY_ITER_ALIGNED|NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
op_dtypes_param = op_dtypes;
op_dtypes[1] = op_dtypes[0];
NPY_UF_DBG_PRINT("Allocating outer iterator\n");