Skip to content

ndarray should have a __numpy_ufunc__ method #6011

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

Closed
njsmith opened this issue Jun 24, 2015 · 3 comments
Closed

ndarray should have a __numpy_ufunc__ method #6011

njsmith opened this issue Jun 24, 2015 · 3 comments

Comments

@njsmith
Copy link
Member

njsmith commented Jun 24, 2015

As per #5986 (comment)

CC: @mhvk

@mhvk
Copy link
Contributor

mhvk commented Jun 24, 2015

Thanks!

@njsmith
Copy link
Member Author

njsmith commented 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__ 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).

Kinda ugly all around though...

@seberg
Copy link
Member

seberg commented Jan 3, 2019

It seems ndarray.__array_ufunc__ exists nowadays, so closing.

@seberg seberg closed this as completed Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants