-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Should __array_function__ allow overriding arange, linspace, etc? #12379
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
Comments
I think this makes sense, at least for all but Possibly a way to tell whether something should get an |
I agree that at least in principle In any case, I see that In principle perhaps |
Agreed that casting to Not sure about (Aside: the |
I sent an email about arrays in linspace to the mailing list.
…On Wed, Nov 14, 2018 at 9:29 AM Marten van Kerkwijk < ***@***.***> wrote:
Agreed that casting to array is a dead giveaway for allowing
__array_ufunc__!
Not sure about arange - on the one hand I don't really see how it hurts
to allow overrides, on the other I recall a mess in discussions about what
should happen for something as simple as complex numbers and feel we
shouldn't make a (slightly) bad situation worse. So, I'd be quite happy too
with explicitly noting that, really, here one does deal with a case where
the arguments should be integers and certainly scalar, and that hence we
won't extend it.
(Aside: the arange docstring is very python2 specific, stating that range
returns a list... In some sense, one would like an arange object that
auto-evaluates...)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#12379 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABKS1tkt0pw_RJs9MyvaMm0DlsqAyga0ks5uvFMAgaJpZM4YcGyI>
.
|
|
We never resolved what to do about |
Will close this for now, since arange has the |
xref #12028 yt-project/unyt#50
NumPy has a handful of construction functions that accept scalars as arguments to control their bounds, e.g.,
arange
,linspace
,logspace
andgeomspace
.The general rule we've been using for
__array_function__
is that it's only called on array-like arguments, so array construction functions are excluded. This makes a lot of sense for functions likenp.zeros
, where there's no possible way to infer the return type based merely on the shape. But forarange
andlinspace
, we could defer to the__array_function__
overrides on the scalar arguments.This would be particularly useful for scalar types implementing a unit system. (I believe we already support
datetime64
in some of these constructors, but of course that's doable only because datetime64 is built into NumPy.)CC @mhvk
The text was updated successfully, but these errors were encountered: