-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
ENH: __array_function__
for multiarray functions
#12175
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
Conversation
Notes/questions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a comment about use of None
in where
- not sure how best to solve that... Revenge of the object dtype!
More generally, except perhaps for where
, I think the extra overhead for these functions would generally be acceptable, as the work they do is fairly complex (for empty_like
, in filling the newly created array).
In any case, it seems worth extending this especially to concatenate
, even if right now it makes things a little slower.
The only disadvantage that I can see is related to the arguments: if we now allow keyword arguments, we're stuck with them, and in C that is so slow that we are effectively stuck with the python wrapper. But, again, in practice I think the benefits well outweigh these disadvantages.
I also tend to think the tradeoffs are worth it here. Even if |
I finished implementing multiarray overloads with NumPy wrappers. The most awkward part was for a few datetime functions, because their docstrings lie about their function signatures -- they claim to accept |
The Azure build failure looks spurious -- is there an easy way for me to reset that? |
@shoyer I restarted the build manually. I added your google email address to Azure devops admin group--not sure if you have a different Microsoft account though. |
Thanks Tyler! If you could add my personal Gmail address (my GitHub username at Gmail.com) that would be great. |
@tylerjereddy You can rerun the failing test by itself; click on the failing test so that it shows, pull down the three dot menu up top, and hit rebuild. |
@charris I thought I did that, but maybe I failed to properly select so the whole matrix was re-triggered by accident |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have anything to add, this looks all good to me.
Since my comment about |
__array_function__
for multiarray functions
The original motivation for the style of these wrapper functions, introduced in numpygh-12175, was to preserve introspection. But it turns out NumPy's functions defined in C don't support introspection anyways, so the extra wrapper functions are entirely pointless. This version reverts the additional wrapper functions, which put default arguments in two places and introduced slow-down due to the overhead of another function call. I've retained docstrings in multiarray.py, since it's definitely more readable to keep docstrings and dispatchers together rather than leaving docstrings in _add_newdocs.py. One bonus of this approach is that dispatcher functions have the same name as their implementations, so `np.concatenate(unknown=True)` gives an error message mentioning "concatenate" rather than "_concatenate_dispatcher": `TypeError: concatenate() got an unexpected keyword argument 'unknown'`
Testing out the Python wrapper approach.
xref #12028