BUG: linalg: emit a MemoryError on a malloc failure#29811
Conversation
Otherwise, a malloc failure in `init_gesv(...)` is not acted upon, and the python return value is silently wrong.
|
Using Thanks, this is right, but TBH, a bit half hearted. The same function is called in multiple places, but only one is fixed. |
|
Thanks---yes, the initial attempt was exploratory, to double-check that the general direction makes sense. Now that you confirmed it (thanks!), the updated PR extends this check across The error message is not as nice as it is for other memory failures which are reported through |
| NPY_ALLOW_C_API; | ||
| PyErr_NoMemory(); | ||
| NPY_DISABLE_C_API; | ||
| } |
There was a problem hiding this comment.
Let's go with this, npy_gil_error, got enough other places.
|
Seems simple and enough and very safe to backport as well. |
Otherwise, a malloc failure in `init_gesv(...)` etc. is not acted upon, and the python return value is silently wrong.
Otherwise, a malloc failure in `init_gesv(...)` etc. is not acted upon, and the python return value is silently wrong.
Otherwise, a malloc failure in `init_gesv(...)` etc. is not acted upon, and the python return value is silently wrong.
BUG: linalg: emit a MemoryError on a malloc failure (#29811)
Otherwise, a malloc failure in `init_gesv(...)` etc. is not acted upon, and the python return value is silently wrong.
Otherwise, a malloc failure in
init_gesv(...)is not acted upon, and the python return value is silently wrong---inv(non_zero_array)returns an array of zeros.On main, using the script under the fold,
numpy._core._exceptions._ArrayMemoryError: Unable to allocate 191. MiB for an array with shape (5000, 5000) and data type float64from somewhere else in the gufunc machinery;resbe an array of all zeros, no error.Note that I don't know what I'm doing with
NPY_ALLOW_C_API_DEFetc ---here I simply parrot the macros from elsewhere in this source file, e.g. https://github.com/numpy/numpy/blob/main/numpy/linalg/umath_linalg.cpp#L1202The same issue seems present in other linalg functions, so if this fix looks reasonable, I'll extend to other functions.
Details