You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
ndarray should have a __numpy_ufunc__ method #6011
One complication to consider: if the presence of __numpy_ufunc__ disables __array_wrap__ and friends (as it currently does), then carelessly adding __numpy_ufunc__ to ndarray might cause existing subclasses to break.
I guess the most practical way to implement ndarray.__numpy_ufunc__ in the short term would be to teach the ufunc machinery to (as a special case) ignore the presence of this particular __numpy_ufunc__ method when seen, and then its implementation could be
def __numpy_ufunc__(self, ...):
if <there are any objects with __numpy_ufunc__ methods>:
return NotImplemented
else:
return getattr(ufunc, method)(...)
and this would both avoid infinite recursion and allow subclasses to still take advantage of the __array_wrap__ stuff (since while they would inherit a __numpy_ufunc__ implementation, it would be ignored).
Activity
mhvk commentedon Jun 24, 2015
Thanks!
njsmith commentedon Jun 24, 2015
One complication to consider: if the presence of
__numpy_ufunc__disables__array_wrap__and friends (as it currently does), then carelessly adding__numpy_ufunc__tondarraymight cause existing subclasses to break.I guess the most practical way to implement
ndarray.__numpy_ufunc__in the short term would be to teach the ufunc machinery to (as a special case) ignore the presence of this particular__numpy_ufunc__method when seen, and then its implementation could beand this would both avoid infinite recursion and allow subclasses to still take advantage of the
__array_wrap__stuff (since while they would inherit a__numpy_ufunc__implementation, it would be ignored).Kinda ugly all around though...
seberg commentedon Jan 3, 2019
It seems
ndarray.__array_ufunc__exists nowadays, so closing.