summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2018-12-03 09:43:37 -0800
committermattip <matti.picus@gmail.com>2018-12-03 09:43:37 -0800
commit18476f5285bdd3f1405086e37240a9bd2640ff16 (patch)
treeaac6f6a3d6d1b2e304b3ac27004da49299df833c /numpy
parent72f2abf34a43cf3642acf6a6ff951148051404ae (diff)
downloadnumpy-18476f5285bdd3f1405086e37240a9bd2640ff16.tar.gz
DOC: add a comment detailing the output ufunc flag choices
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/umath/ufunc_object.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 5dc1db226..ea0007a9d 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -328,6 +328,18 @@ set_matmul_flags(PyObject *d)
if (matmul == NULL) {
return -1;
}
+ /*
+ * The default output flag NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE allows
+ * perfectly overlapping input and output (in-place operations). While
+ * correct for the common mathematical operations, this assumption is
+ * incorrect in the general case and specifically in the case of matmul.
+ *
+ * NPY_ITER_UPDATEIFCOPY is added by default in
+ * PyUFunc_GeneralizedFunction, which is the variant called for gufuncs
+ * with a signature
+ *
+ * Enabling NPY_ITER_WRITEONLY can prevent a copy in some cases.
+ */
((PyUFuncObject *)matmul)->op_flags[2] = (NPY_ITER_WRITEONLY |
NPY_ITER_UPDATEIFCOPY |
NPY_UFUNC_DEFAULT_OUTPUT_FLAGS) &