Skip to content

ndarray should have a __numpy_ufunc__ method #6011

Closed

Description

@njsmith

Activity

  1. mhvk commented on Jun 24, 2015

    @mhvk
    Contributor

    Thanks!

  2. njsmith commented on Jun 24, 2015

    @njsmith
    MemberAuthor

    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...

  3. seberg commented on Jan 3, 2019

    @seberg
    Member

    It seems ndarray.__array_ufunc__ exists nowadays, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions