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.) */
| 599 | * way to tell. (E.g., when converting to a read-write buffer.) |
| 600 | */ |
| 601 | NPY_NO_EXPORT int |
| 602 | array_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 | * |
no test coverage detected