Skip to content

MAINT: post __array_ufunc__ merger to-do list #8892

Closed

Description

@mhvk

EDITED to update with items from @eric-wieser and @shoyer. Feel free to edit to add other items.

A reminder of clean-up after #8247 that could most usefully be done:

Activity

  1. changed the title [-]MAINT: ufunc argument normalization should be unified (post __array_ufunc__)[/-] [+]MAINT: post __array_ufunc__ merger to-do list[/+] on Apr 5, 2017
  2. mattip commented on Apr 10, 2018

    @mattip
    Member

    issue #9028 is marked for 1.15. Are there any other of these tasks that should also be in 1.15?

  3. mhvk commented on Apr 10, 2018

    @mhvk
    ContributorAuthor

    @mattip - the list is fairly complete, and all should at some point be solved... But I think the __matmul__ one is by far the most annoying/urgent..

  4. mattip commented on Dec 12, 2018

    @mattip
    Member

    updated - matmul is now a ufunc

  5. seberg commented on Dec 13, 2019

    @seberg
    Member

    I am not sure about this, is it considered a bug that __array_ufunc__ currently will pass on additional keywords (not supported by numpy) happily, or is that intentional?

  6. mhvk commented on Dec 13, 2019

    @mhvk
    ContributorAuthor

    I'd think it is a bug and (too implicitly) part of the first item above.

  7. seberg commented on Dec 13, 2019

    @seberg
    Member

    Looking at faster argparsing, I was starting to clean that up a bit (hopeully actually making it cleaner). That would "fix" that, but was not sure if I would have to add a cludge for it. Unfortunately it will be one hell of a merge conflict with my dtypes branch, but overall maybe it will make things easier anyway, since that needs a lot of cleanup as well.

  8. mhvk commented on Dec 13, 2019

    @mhvk
    ContributorAuthor

    This is something I'm still interested in 😄 - possibly it can be made easier by aiming at the new fast call interface in python 3.8 (still private, but good for experiments; https://docs.python.org/3/whatsnew/3.8.html#vectorcall-a-fast-calling-protocol-for-cpython

    p.s. My abandoned speed-up attempts are in #11372. Possibly individual commits are still useful. It definitely was a big mistake to try to do many things at once, though...

  9. seberg commented on Dec 13, 2019

    @seberg
    Member

    @mhvk yes, I am doing that, although my code right now has #ifdef to support both. If python is much faster on its side, it may help, otherwise I am not so sure. kwargs are pretty rare for usual ufunc calls (but very common for reduce). So for usual ufunc calls, my hope is currently mainly deleting some code duplication.

    Anyway, halfway there, the review/some cleanup will be a pain though.

  10. seberg commented on Dec 13, 2019

    @seberg
    Member

    @mhvk geee, I did not realize that bunch of code/changes from you were lurking around. Will have a look at it, since you seemed to have gotten something out here, probably there are some thing I can copy over easily.

  11. seberg commented on Dec 16, 2019

    @seberg
    Member

    @mhvk I realize that I need to clean it up a bit, but would you be willing to take some look at the ufunc side of trying to get METH_FASTCALL at some point? (and vectorcall, but I am not sure it is really all that much worth it for now. ufunc.__call__ is often called without keywords I think, and it has a pretty high overhead in any case).
    It is a pretty huge diff though, so I can understand if its too much :/

    An initial diff is here (I need to clean it out, and maybe squash it). Some of the things I did:

    1. Parse all arguments to object initially
    2. Always construct full_args (tuples of input and output arguments)
    3. Use full_args tuples inside the overrides, so that it does not need to do any parsing/dict manipulation (unless one of the inputs/outputs supports __array_ufunc__).

    This also moves the argument parsing to the initial ufunc_generic_call basically, and what you did also, moves the split betwen gufuncs up to there. (I am not 100% positive I already wrote the shim for the old PyUfunc_GenericFunction, which is an annoying C-API, that nobody uses.

    https://github.com/seberg/numpy/compare/2d5b87e9f4837b70c068e832bd347b6b454e3bde..24ecc53f4d7a704d3ad0473d04550ba4539dabe6

  12. mhvk commented on Dec 29, 2019

    @mhvk
    ContributorAuthor

    @seberg - I had an initial look and very much like the simplification in the processing order! I see you circumvented the annoyance I had of some functions being in the API which really are not handy any more (but likely are never used...).

    One note on keyword arguments: if they were parsed as quickly as positional, it would actually become useful to pass out to ufuncs, which is much more readable than positional.

  13. seberg commented on Jan 2, 2020

    @seberg
    Member

    Thanks for having a look. I will split out the things into 3 (or 4) PRs, it hangs a bit on us being OK to duplicate some of the work that C-Python also semi-privdes with argument parsing.

    Using kwargs are still quite a bit slower, but the speed difference is much smaller than before. For module level functions though, nothing much changes: __array_function__ just adds too much overhead and cannot leverage METH_FASTCALL.

  14. seberg commented on Mar 23, 2021

    @seberg
    Member

    Marked first two as done, since gh-15271 covers them.

  15. seberg commented on May 20, 2022

    @seberg
    Member

    Going to close this, I don't think keep this open serves much purpose anymore:

    • Yes, we can add more documentation...
    • The ABC stuff might be intersting (not sure), but also has its own issue.
    • Overriding __eq__ for voids, should not likely be solved by making void comparisons a ufunc (non-trivial, but I still think that is probably the right way)
    • The idea of refactoring how __array_ufunc__ entry-point may be interesting, but I am not sure and keeping it around here won't make it happen.
  16. mhvk commented on May 20, 2022

    @mhvk
    ContributorAuthor

    Yes, makes sense to close - the one that is still a buglet has its own issue anyway.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions