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

Function array_might_be_written

numpy/core/src/multiarray/arrayobject.c:601–622  ·  view source on GitHub ↗

Call this from contexts where an array might be written to, but we have no * way to tell. (E.g., when converting to a read-write buffer.) */

Source from the content-addressed store, hash-verified

599 * way to tell. (E.g., when converting to a read-write buffer.)
600 */
601NPY_NO_EXPORT int
602array_might_be_written(PyArrayObject *obj)
603{
604 const char *msg =
605 "Numpy has detected that you (may be) writing to an array with\n"
606 "overlapping memory from np.broadcast_arrays. If this is intentional\n"
607 "set the WRITEABLE flag True or make a copy immediately before writing.";
608 if (PyArray_FLAGS(obj) & NPY_ARRAY_WARN_ON_WRITE) {
609 if (DEPRECATE(msg) < 0) {
610 return -1;
611 }
612 /* Only warn once per array */
613 while (1) {
614 PyArray_CLEARFLAGS(obj, NPY_ARRAY_WARN_ON_WRITE);
615 if (!PyArray_BASE(obj) || !PyArray_Check(PyArray_BASE(obj))) {
616 break;
617 }
618 obj = (PyArrayObject *)PyArray_BASE(obj);
619 }
620 }
621 return 0;
622}
623
624/*NUMPY_API
625 *

Callers 1

Calls 3

PyArray_FLAGSFunction · 0.85
PyArray_CLEARFLAGSFunction · 0.85
PyArray_BASEFunction · 0.85

Tested by

no test coverage detected