-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
ENH: add copy parameter for api.reshape function #23789
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
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c19e84e
BUG: add copy parameter for api.reshape function
bwalshe 78923f0
fixup: linting issue
bwalshe 8bc1478
fixup: linting issue
bwalshe 6535f88
enable copy=False
bwalshe 38444c5
fixup: more linter issues
bwalshe 0d831f0
release note
bwalshe 5822464
Shorten release note to single point
bwalshe 8c184b5
delete 23789.new_feature.rst from this PR
mattip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
BUG: add copy parameter for api.reshape function
This adds a parameter to api.reshape to specify if data should be copied. This parameter is required so that api.reshape conforms to the standard. See #23410
- Loading branch information
commit c19e84e012da65828f62f54f721337d873fd04fe
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from numpy.testing import assert_raises | ||
import numpy as np | ||
|
||
from .. import all | ||
from .._creation_functions import asarray | ||
from .._dtypes import float64, int8 | ||
from .._manipulation_functions import ( | ||
concat, | ||
reshape, | ||
stack | ||
) | ||
|
||
|
||
def test_concat_errors(): | ||
assert_raises(TypeError, lambda: concat((1, 1), axis=None)) | ||
assert_raises(TypeError, lambda: concat([asarray([1], dtype=int8), asarray([1], dtype=float64)])) | ||
|
||
|
||
def test_stack_errors(): | ||
assert_raises(TypeError, lambda: stack([asarray([1, 1], dtype=int8), asarray([2, 2], dtype=float64)])) | ||
|
||
|
||
def test_reshape_copy(): | ||
a = asarray([1]) | ||
b = reshape(a, (1, 1), copy=True) | ||
a[0] = 0 | ||
assert all(b[0, 0] == 1) | ||
assert all(a[0] == 0) | ||
assert_raises(NotImplementedError, lambda: reshape(a, (1, 1), copy=False)) | ||
|
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.
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.
I think this can be implemented by calling
reshape
and raising an exception if the result is not a view. Or maybe there's even a more direct way to tell ifreshape
will copy without actually trying it.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.
I guess we need to implement it directly in
np.reshape
. Do others have issues with the above simple workaround here for now though?Uh oh!
There was an error while loading. Please reload this page.
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.
I think that in order to do this correctly, I might have to change the signature of the
PyArray_Newshape(PyArrayObject *self, PyArray_Dims *newdims, NPY_ORDER order)
function innumpy/core/src/multiarray/shape.c
, but this has been marked asNUMPY_API
in the comments.I can make the change you suggested above, but if I want to go ahead with the change to
PyArray_Newshape
, what do I have to do to get approval for that?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.
@asmeurer Do these changes look OK?