Called at module initialization to set the matmul ufunc output flags */
| 345 | |
| 346 | /* Called at module initialization to set the matmul ufunc output flags */ |
| 347 | NPY_NO_EXPORT int |
| 348 | set_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 | /* |
no outgoing calls
no test coverage detected