-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
BUG: linalg: emit a MemoryError on a malloc failure #29811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
seberg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ev-br! Awesome, this looks pretty now and a cleanup :).
| NPY_ALLOW_C_API; | ||
| PyErr_NoMemory(); | ||
| NPY_DISABLE_C_API; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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