-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
BUG: make void-scalar getfield/setfield use ndarray methods #5947
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* checks on the field datatypes and because it broadcasts properly. | ||
* However, as a special case, void-scalar assignment broadcasts | ||
* differently from ndarrays when assigning to an object field: Assignment | ||
* to an ndarray object field brodcasts, but assignment to a void-scalar |
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.
brodcasts -> broadcasts.
Looks generally good. |
This commit modifies voidtype_get/setfield to call ndarray's get/setfield, which does proper safety checks (for object arrays) and broadcasts properly. This solves bugs related to void-scalar assignment. Also changed the calling convention of voidtype_getfield. Previously it accepted a (dtype, offset, title) tuple and dropped title. Now it expects only (dtype, offset), just like ndarray's getfield. Fixes numpy#3126. Fixes numpy#3561.
3a8e98e
to
df959ed
Compare
All right, updated. |
OK, let's give this a shot. Thanks @ahaldane . |
charris
added a commit
that referenced
this pull request
Jun 11, 2015
BUG: make void-scalar getfield/setfield use ndarray methods
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a continuation of #5642.
This PR removes most of the logic in
voidtype_getfield
andvoidtype_setfield
. Instead they simply call the ndarraygetfield
andsetfield
. This solves bugs related to void-scalar assignment, #3126 and #3561. It also makes these functions safer since ndarray's get/setfield does safety checks to avoid segfaults involving object arrays.Additional minor notes:
I changed the calling convention of
voidtype_getfield
. Previously it accepted(dtype, offset, title)
and dropped the (optional) title. Now it expects only(dtype, offset)
, just like ndarray getfield. This simplifies thevoidtype_getfield
code.I also removed code that does byteswapping in both getfield and setfield. After looking at it for a while, I am pretty convinced this code is unnecessary since in both cases we use
gentype_generic_method
to convert the void scalar to a 0-d ndarray, do the get/setfield, and then convert the returned value to a scalar usingPyArray_ToScalar
(inPyArray_Return
).PyArray_ToScalar
already does the byteswap for us. Therefore, any scalars that reachvoidtype_getfield
are already in NBO and there is no need to swap again.Also, at the end of
voidtype_setfield
I effectively doarr[()] = val
, and actually create an empty tuple object. Is that really the best way to use setfield, given that arr is possible 0-d?