Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Fix fftn failure when both out and s parameters are given #28895

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

shibozhou
Copy link

Fixes #28890

Problem

When N-dim FFTs are calculated using fftn, the code performs a loop over all axes, applying 1D FFts in sequence. However, when both out and s are specified, intermediate transforms change the array shape, making the out parameter incompatible with these intermediate results.

Solution

This pr changes the _raw_fftnd to only use the out parameter for the final transformation, not for intermediate steps. The current function works correctly when both out and s have different shapes than the input array.

Test

The added test case verifies the fix with an input array of shape (4, 4, 4) and an output with shape (6, 6, 6)

@shibozhou
Copy link
Author

Looks like a pypy issue. Similar to #28469 what they encountered.

@ngoldbaum ngoldbaum requested a review from mhvk May 5, 2025 15:03
if out is not None and s is not None and any(s[i] != a.shape[axes[i]] for i in range(len(axes))):
intermediate_out = None
else:
intermediate_out = out
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it bring any performance improvement if we pass a itself when possible as out in intermediate steps (when out is originally None)? We might not be able to do so in the first iteration tough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: N-D FFTs fail when both out and s are given
2 participants