MCPcopy Create free account
hub / github.com/numpy/numpy / set_matmul_flags

Function set_matmul_flags

numpy/core/src/umath/ufunc_object.c:347–371  ·  view source on GitHub ↗

Called at module initialization to set the matmul ufunc output flags */

Source from the content-addressed store, hash-verified

345
346/* Called at module initialization to set the matmul ufunc output flags */
347NPY_NO_EXPORT int
348set_matmul_flags(PyObject *d)
349{
350 PyObject *matmul = _PyDict_GetItemStringWithError(d, "matmul");
351 if (matmul == NULL) {
352 return -1;
353 }
354 /*
355 * The default output flag NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE allows
356 * perfectly overlapping input and output (in-place operations). While
357 * correct for the common mathematical operations, this assumption is
358 * incorrect in the general case and specifically in the case of matmul.
359 *
360 * NPY_ITER_UPDATEIFCOPY is added by default in
361 * PyUFunc_GeneralizedFunction, which is the variant called for gufuncs
362 * with a signature
363 *
364 * Enabling NPY_ITER_WRITEONLY can prevent a copy in some cases.
365 */
366 ((PyUFuncObject *)matmul)->op_flags[2] = (NPY_ITER_WRITEONLY |
367 NPY_ITER_UPDATEIFCOPY |
368 NPY_UFUNC_DEFAULT_OUTPUT_FLAGS) &
369 ~NPY_ITER_OVERLAP_ASSUME_ELEMENTWISE;
370 return 0;
371}
372
373
374/*

Callers 1

PyInit__multiarray_umathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected