Open
Description
Describe the issue:
UFuncs seem to not handle array priority wrapping quite right (at least compared to np.get_array_wrap
). That is, they simply skip NumPy arrays and scalars, but that is not necessarily right.
(The code should probably flag their existence, and return NULL
manually when that makes sense)
(Noticed in gh-21262)
Reproduce the code example:
import numpy as np
class myarr(np.ndarray):
__array_priority__ = -1
a = np.arange(3)
b = np.arange(3).view(myarr)
# although priority is negative, `myarr` is used:
assert type(np.multiply(a, b)) is myarr
assert type(np.multiply(b, a)) is myarr
# But this is not true for the Python helper:
res = np.arange(3)
assert type(np.get_array_wrap(a, b)(res)) is np.ndarray
Error message:
No response
NumPy/Python version information:
1.22.x/1.23.
Possible project
I think fixing this is a small nice project. It should not be very hard, but requires to dig a bit into the code for universal functions and experience with the Python C-API (or willingness to learn).
Fixing it may also require an iteration or two to figure out the best way to do it. But I expect we should adjust the ufunc code and that would make the issue very localized.