-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add support for copy
kwarg in astype
to match Array API
#20195
Conversation
dfd35ab
to
a877182
Compare
Suggestion: let's implement these changes in Then we can just call Also we could add some test coverage in |
2395e76
to
46e1060
Compare
46e1060
to
6856b94
Compare
6856b94
to
3799152
Compare
One small suggestion: it may be helpful to separate the |
Agreed. For now I'm just factoring out the device semantics as mentioned here and leaving only the changes to |
3799152
to
2215021
Compare
device
kwarg in astype
to match Array APIcopy
kwarg in astype
to match Array API
I've created this PR in my fork to track discussion regarding device movement semantics using |
ffb25b8
to
a293acc
Compare
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.
Thanks!
Oh, it looks like this branch has conflicts that need to be resolved before we can merge. |
a293acc
to
3daa84b
Compare
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.
Actually, I'm a bit worried about this change. In a lot of places we implicitly depend on x.astype(x.dtype)
being a no-op, and now that the default semantics are copy=True
, I think this assumption will no longer hold.
Maybe we should default to copy=None
so that the default is backward-compatible?
NumPy has made a similar exception for copy
in astype
: https://numpy.org/neps/nep-0056-array-api-main-namespace.html#copy-keyword-semantics
If it is causing that many problems, then I agree going the gentler deprecation route as opposed to the "bug-fix" route should be preferred.
Maybe we wait to see what the community consensus on the proposal is, that way we can tune the numpy namespace to the |
It seems like the array API will be sticking with I think what we should do here is follow NumPy and the Array API on the semantics of the In JAX, there's almost never a reason to force a copy, because arrays are immutible and copies are expensive. In NumPy, it's the opposite: you almost never want to silently return a view, because arrays are mutable. |
7837e90
to
973e921
Compare
@jakevdp Updated w/ a default of |
973e921
to
1811f8e
Compare
Thanks - I'm still a bit confused about the state of things upstream. It sounds like NumPy does support |
That seems not to be the case in NumPy 1.26, but is indeed true in NumPy 2.0.0rc1 with the caveat that I'm personally hoping we see a change in NumPy and the array API to converge the |
1811f8e
to
bc07964
Compare
bc07964
to
5e2da2d
Compare
5e2da2d
to
30cd3b8
Compare
Towards #20200
cf. data-apis/array-api#665
Note
This PR includes a placeholder utility function for managing device transfer, which will be developed in a follow-up PR
Default behavior is preserved when
copy=None