BUG: unnecessary copy in .astype if the output array is already the… - #468
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR avoids unnecessary array copies in FFT wrappers by passing copy=False to .astype(...) when enforcing expected output dtypes. This improves performance for backends (notably NumPy >= 2.0 and current CuPy) that already return the desired dtype.
Changes:
- Update FFT wrapper functions to use
res.astype(target_dtype, copy=False)when normalizing output dtypes forfloat32/complex64inputs. - Update
fftfreq/rfftfreqwrappers to usecopy=Falsewhen an explicitdtypeis requested.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
Author
|
The numpy test fails: |
Member
|
CI failures are unrelated, data-apis/array-api-tests#455 |
ev-br
approved these changes
Aug 24, 2026
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
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.
… correct dtype.
The
fftfunctions unnecessarily copy the return array if thedtypeis the desireddtype.I believe the use of
.astypeis to enable support for numpy < 2.0. As support for"f4"and"c8"dtypes was introduced in numpy 2.0 the unnecessary copies only occur in numpy >= 2.0.I'm not sure when cupy stopped upcasting
"f4"and"c8"dtypes in ffts, but it currently doesn't, and therefore also has the unnecessary copy.