-
-
Notifications
You must be signed in to change notification settings - Fork 11k
ENH: Add support for copy modes to NumPy #19173
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
ping @seberg I will keep updating this PR. I have added CopyMode enum as of now. |
As a bit of general (non-C-related) advice: there are quite a few linting related remarks that should ideally be addressed. |
Yeah. I will run the linting tests locally to fix such kind of issues. Thanks for pointing out. |
Co-authored-by: Sebastian Berg <sebastian@sipsolutions.net>
@seberg Is this good to go? |
Probably, I am tempted to push that double checking for the dunder refactor myself. In any case its holiday today, so will only have a close look/do that tomorrow probably. |
No worries. Please feel free to push any changes here. Anything (commits, reviews) that can help in completing this will work for me. |
Yes, these may be slightly biased towards my own opinions.
Doing the check before calling `PyArray_FromArrayAttr` means we look up the attribute twice. It further fixes two bugs: 1. The reference counting was wrong. 2. In debug mode there was a failure for some deprecation warnings (probably due to error propagation)
The first name was `do_copy`, which was confusing because it sounds like a copy is forced (opposite is the case!) `allow_copy` would have been better, but corrects it into the wrong direction. `never_copy` is correct, and aligns with the Python side names
Should be OK now from my side. First thought I would put this in and make a new PR, but the refactor is necessary since the tests were currently failing. |
(There is another missed path above, but I will ignore it, because it is in an ugly deprecated code-path) |
Travis CI is stalled I think. Is there anyway to start the two tests there? Rest of the tests are passing though. |
Restarted - just ignore if they don't complete, they seem to be hanging again. |
Yeah. They appear to be in queue forever. |
Is everyone happy with this? |
I am happy with this, just think someone should sanity check my fixups. |
Thanks @czgdp1807, @seberg |
So one battle I decided to ignore the first time around is that while for For For the buffer protocol, things are even murkier. NumPy somewhat assumes ownership stays with the exporter, but really, the buffer protocol does not guarantee this at all. Python has a hack to try to ensure ownership in one place, but it is a pretty bad guess. (Again, the caveat applies that ownership does not guarantee no-copy per-se, it just makes workflows that do copy difficult and weird.) So... maybe we should refuse the "no copy" stuff completely. Small problem: There is no actual "no copy" protocol remaining for use in The problem is not impossible to solve: E.g. we can aim for So, I am happy to move forward with that other PR, ideally, this one gets restricted down though. Probably together with expanding the |
This PR implements never copy mode in numpy array creation by adding an enum,
np.array_api.CopyMode
which will have three members,ALWAYS
(equivalent toTrue
in current API),IF_NEEDED
(equivalent toFalse
in current API) andNEVER
(the never copy mode). Related NEP - 47.Related Issues
#9818
#11884
#8679
Related PRs
#11897