Skip to content

fix: match SciPy rfft2 positional argument order - #419

Open
vera-rubin wants to merge 2 commits into
IntelPython:masterfrom
vera-rubin:fix/scipy-rfft2-norm
Open

vera-rubin wants to merge 2 commits into
IntelPython:masterfrom
vera-rubin:fix/scipy-rfft2-norm

Conversation

@vera-rubin

@vera-rubin vera-rubin commented Dec 4, 2026 •

Copy link
Copy Markdown

Description

mkl_fft.interfaces.scipy_fft.rfft2 declares overwrite_x before norm, while scipy.fft.rfft2 is rfft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, workers=None, *, plan=None). A call that passes norm positionally, as SciPy allows, binds the string to overwrite_x and the normalization is silently ignored. For a 2x2 array of ones this returns (4+0j) instead of SciPy's (2+0j):

import numpy as np
from mkl_fft.interfaces import scipy_fft
x = np.ones((2, 2), dtype=np.float64)
print(scipy_fft.rfft2(x, None, (-2, -1), "ortho")[0, 0])

The same happens through scipy.fft.set_backend(mkl_fft.interfaces.scipy_fft, only=True): SciPy forwards positional arguments to the backend unchanged, so scipy.fft.rfft2(x, None, (-2, -1), "ortho") also ignored norm there. With the order fixed, overwrite_x passed as the fifth positional argument also behaves as in SciPy (before, it raised ValueError: Invalid norm value False).

The fix puts norm before overwrite_x, as in SciPy and as the other functions in this module already do (rfft2 was the only one with the two swapped). A regression test compares the positional call with scipy.fft.rfft2 for all four norm values and both real precisions; it fails for "forward" and "ortho" without the fix and passes with it.

Verification

Linux x86_64, Python 3.12.3, NumPy 2.5.5, SciPy 1.18.1, MKL 2026.2, built with pip install -e . --no-build-isolation on master 84ce3f4.

  • Tests: python -m pytest mkl_fft/tests -q: 2817 passed, 2 skipped (without the fix: the 4 new forward/ortho cases fail, everything else passes).
  • The new test calls require_scipy_fft() first, like the other scipy_fft tests, so it skips where mkl-service is not installed (the Python 3.15 wheel jobs). Without mkl-service: 8 skipped; with it: 8 passed.
  • Lint: not run locally.

Not verified

Pre-commit hooks, Windows and macOS: left to CI.

Checklist

  • NumPy/SciPy FFT API compatibility preserved, or the break is intentional and called out above.
  • Behavior changes have tests in mkl_fft/tests/; bug fixes have a regression test.
  • CHANGELOG.md updated under ## [dev] with a [gh-NNN] link, or the change isn't user-visible.

ChipLab's AI agents
Nathan Chandrasekar

Copilot AI balanced review requested due to automatic review settings December 4, 2026 01:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@antonwolfy antonwolfy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix is right: rfft2 now has the same signature as scipy.fft.rfft2, and it was the only function in scipy_fft or numpy_fft whose signature differed from SciPy 1.18.1 / NumPy 2.5.5. But the new test fails CI (inline).

CI. Test Linux Wheels and Test Windows Wheels for Python 3.15 and 3.15t fail, each only on the 8 cases of test_scipy_rfft2_positional_norm, with AttributeError: module 'mkl_fft.interfaces' has no attribute 'scipy_fft'. Those jobs install SciPy but not mkl-service (python_version < "3.15" marker), so mkl_fft.interfaces has no scipy_fft there. All other jobs pass.

scipy.fft.set_backend was affected too. SciPy forwards positional arguments to the backend unchanged, so on master scipy.fft.rfft2(x, None, (-2, -1), "ortho") inside scipy.fft.set_backend(mkl_fft.interfaces.scipy_fft, only=True) also ignored norm; with this PR it matches SciPy. Worth a line in the description, since the bug was not limited to direct calls.

Also checked, no issues: SciPy has had norm before overwrite_x in rfft2 since 1.4, so every supported SciPy was affected; nothing in the repo calls rfft2 positionally; overwrite_x passed as the 5th positional argument now behaves like SciPy (on master it raised ValueError: Invalid norm value False).

Comment thread mkl_fft/tests/test_interfaces.py Resolved
Comment thread CHANGELOG.md Resolved
Comment thread mkl_fft/tests/test_interfaces.py Resolved
@antonwolfy antonwolfy added this to the 2.5.0 release milestone Dec 5, 2026
vera-rubin added a commit to vera-rubin/mkl_fft that referenced this pull request Dec 5, 2026
The Python 3.15 wheel test jobs install SciPy but not mkl-service, so
mkl_fft.interfaces has no scipy_fft there. Call require_scipy_fft()
first, as the other scipy_fft tests do. Also link the changelog entry
to IntelPythongh-419.
@vera-rubin

Copy link
Copy Markdown
Author

Thanks for the review. Pushed d4e2512: the new test now calls require_scipy_fft() first, so it skips where mkl-service is not installed, and the changelog entry links gh-419. Checked on Linux with Python 3.12: without mkl-service the 8 cases skip (on da4f182 they failed with the same AttributeError), with it they pass, and the full suite gives 2817 passed, 2 skipped.

Agreed on set_backend: before this change, scipy.fft.rfft2(x, None, (-2, -1), "ortho") under scipy.fft.set_backend(mkl_fft.interfaces.scipy_fft, only=True) also ignored norm, and overwrite_x as the fifth positional argument raised ValueError: Invalid norm value False. Both now behave as in SciPy.

I left the signature test out to keep this PR to rfft2. I can add it here or in a separate PR, whichever you prefer.

@antonwolfy antonwolfy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you for the contribution and the quick fixes! Both points are addressed and CI is green. A separate follow-up PR for the signature-parity test is fine with me.

The Python 3.15 wheel test jobs install SciPy but not mkl-service, so
mkl_fft.interfaces has no scipy_fft there. Call require_scipy_fft()
first, as the other scipy_fft tests do. Also link the changelog entry
to IntelPythongh-419.
@antonwolfy
antonwolfy force-pushed the fix/scipy-rfft2-norm branch from d4e2512 to dcd0c73 Compare December 6, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants