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 }}
Repository navigation
Defining overrides for aliased NumPy functions in NumPy #13877
There are handful of NumPy functions that are implemented as aliases of other NumPy function. These include at least min, max, round (non-ufuncs) and abs (an alias of the np.absolute ufunc):
from .fromnumericimportamaxasmax, aminasmin, round_asround
from .numericimportabsoluteasabs
Because np.min is defined as amin, that's also how you have to override the function with __array_function__. This leads to surprising behaviors for libraries like dask, which wrote its __array_function__ method to alias numpy functions to dask/cupy functions of the same name: because dask.array.amin does not exist, numpy.min (an alias for numpy.amin) doesn't work: dask/dask#5031
Things we could do about this on the NumPy side:
Nothing -- the error message is clear enough. Dask can implement amin/amax easily enough.
Define separate wrapper functions, so they can be overridden by the name users specify. Interestingly this is already the case for round_, which is a wrapper around around.
I think option (2) makes sense for min, max and round. It's not a great option for abs, since that would mean it no longer goes through __array_ufunc__.
It doesn't sound to me like we need to do anything for abs/absolute -
they're two names for the same ufunc, so neither are affected by the
__array_function__ mechanism. Even the dask __array_ufunc__ can pick its
favorite spelling, and because they're aliases will automatically work for
both.
On Sun, Jun 30, 2019, 22:21 Ralf Gommers ***@***.***> wrote:
Nothing -- the error message is clear enough. Dask can implement amin/amax
easily enough.
That's forcing API pollution though ....
For abs we could switch around the names and make absolute the alias.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#13877?email_source=notifications&email_token=AADH2LBFOZRJTKNPWWMLKZLP5GH5PA5CNFSM4H4OXQRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODY5AQVI#issuecomment-507119701>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADH2LA7Z66WK67CEZDAOHLP5GH5PANCNFSM4H4OXQRA>
.
Activity
rgommers commentedon Jul 1, 2019
That's forcing API pollution though ....
For
abswe could switch around the names and makeabsolutethe alias. EDIT: actually we could do that for all of thoseeric-wieser commentedon Jul 1, 2019
shoyer commentedon Jul 1, 2019
I agree that it would make sense to reverse the aliases for
min/max/round. Certainly these names are much more commonly used.I agree that we can probably leave
absoluteas is.rgommers commentedon Mar 25, 2020
We discussed this in the triage meeting:
So just switch the aliases and close this seems like the way to go.
DOC: add `np.round` to the html docs, and make it the preferred alias
MAINT: switch min/max with amin/amax, and add them to html docs
DOC: add `np.round` to the html docs, and make it the preferred alias
MAINT: switch min/max with amin/amax, and add them to html docs
DOC: add `np.round` to the html docs, and make it the preferred alias
MAINT: switch min/max with amin/amax, and add them to html docs