Repository navigation
fix: match SciPy rfft2 positional argument order - #419
vera-rubin wants to merge 2 commits into
Conversation
antonwolfy
left a comment
There was a problem hiding this comment.
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).
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.
|
Thanks for the review. Pushed d4e2512: the new test now calls Agreed on I left the signature test out to keep this PR to |
antonwolfy
left a comment
There was a problem hiding this comment.
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.
d4e2512 to
dcd0c73
Compare
Description
mkl_fft.interfaces.scipy_fft.rfft2declaresoverwrite_xbeforenorm, whilescipy.fft.rfft2isrfft2(x, s=None, axes=(-2, -1), norm=None, overwrite_x=False, workers=None, *, plan=None). A call that passesnormpositionally, as SciPy allows, binds the string tooverwrite_xand the normalization is silently ignored. For a 2x2 array of ones this returns(4+0j)instead of SciPy's(2+0j):The same happens through
scipy.fft.set_backend(mkl_fft.interfaces.scipy_fft, only=True): SciPy forwards positional arguments to the backend unchanged, soscipy.fft.rfft2(x, None, (-2, -1), "ortho")also ignorednormthere. With the order fixed,overwrite_xpassed as the fifth positional argument also behaves as in SciPy (before, it raisedValueError: Invalid norm value False).The fix puts
normbeforeoverwrite_x, as in SciPy and as the other functions in this module already do (rfft2was the only one with the two swapped). A regression test compares the positional call withscipy.fft.rfft2for all fournormvalues 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-isolationon master 84ce3f4.python -m pytest mkl_fft/tests -q: 2817 passed, 2 skipped (without the fix: the 4 newforward/orthocases fail, everything else passes).require_scipy_fft()first, like the otherscipy_ffttests, so it skips where mkl-service is not installed (the Python 3.15 wheel jobs). Without mkl-service: 8 skipped; with it: 8 passed.Not verified
Pre-commit hooks, Windows and macOS: left to CI.
Checklist
mkl_fft/tests/; bug fixes have a regression test.CHANGELOG.mdupdated under## [dev]with a[gh-NNN]link, or the change isn't user-visible.ChipLab's AI agents
Nathan Chandrasekar