-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix: correctly apply fftshift to real-valued data inputs #8407
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
Correctly apply fftshift to real-valued data inputs Signed-off-by: Puyang Wang <[email protected]>
Signed-off-by: Puyang Wang <[email protected]>
Signed-off-by: Puyang Wang <[email protected]>
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.
Pull Request Overview
This pull request fixes the application of fftshift for real-valued data inputs by adjusting how dimension indices are shifted when using torch.view_as_real.
- The expected output in the FFT shift test has been updated to match the corrected behavior.
- In the fft_utils_t module, the logic to compute shift indices has been modified for complex-valued inputs, ensuring consistency between ifftshift and fftshift.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
tests/data/test_fft_utils.py | Updates expected test output to reflect the new fftshift behavior. |
monai/networks/blocks/fft_utils_t.py | Refactors shift index calculation using a transformation on dims for fftshift and ifftshift. |
Comments suppressed due to low confidence (3)
monai/networks/blocks/fft_utils_t.py:194
- [nitpick] The expression '[d - 1 for d in dims]' is used to adjust the dimension indices for FFT operations; consider extracting it into a well-named variable or function to improve readability and clarify its intent.
x = ifftshift(im, [d - 1 for d in dims])
monai/networks/blocks/fft_utils_t.py:203
- [nitpick] The same '[d - 1 for d in dims]' transformation is used here; consider refactoring it to avoid repetition and enhance clarity on why the indices are shifted by one.
out: Tensor = fftshift(x, [d - 1 for d in dims])
tests/data/test_fft_utils.py:24
- Verify that the updated expected output aligns with the corrected fftshift behavior for both real-valued and complex-valued inputs, ensuring full coverage of the new logic.
[[[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]], [[0.0, 0.0], [3.0, 0.0], [0.0, 0.0]], [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]]
Signed-off-by: Puyang Wang <[email protected]>
Signed-off-by: Puyang Wang <[email protected]>
Signed-off-by: Puyang Wang <[email protected]>
Thanks for the contribution, Puyang. @XwK-P |
Signed-off-by: Puyang Wang <[email protected]>
Signed-off-by: Puyang Wang <[email protected]>
Hi @tangy5, would you be willing to fully review and approve is nothing is needed? I don't use these functions so it's hard to comment on correctness. Thanks! |
/build |
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.
Thanks for the update, LGTM.
@tangy5, let me know if you have any concern. Thanks.
Correctly apply fftshift to real-valued data inputs
Fixes # .
Description
Correctly apply fftshift to real-valued data inputs. The last dimension of output of torch.view_as_real has size 2 for both real-valued and complex-valued input.
Types of changes
./runtests.sh -f -u --net --coverage
../runtests.sh --quick --unittests --disttests
.make html
command in thedocs/
folder.