Repository navigation
fix: match SciPy rfft2 positional argument order - #419
vera-rubin wants to merge 1 commit 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).
| @pytest.mark.parametrize("norm", [None, "forward", "backward", "ortho"]) | ||
| @pytest.mark.parametrize("dtype", [np.float32, np.float64]) | ||
| def test_scipy_rfft2_positional_norm(norm, dtype): | ||
| sp_fft = pytest.importorskip("scipy.fft", reason="requires scipy") |
There was a problem hiding this comment.
This fails the four Python 3.15 wheel test jobs: mkl-service is not installed there, so mfi.scipy_fft does not exist and all 8 cases raise AttributeError instead of skipping. importorskip("scipy.fft") only covers a missing SciPy. The other scipy_fft tests in this file call require_scipy_fft() first:
| sp_fft = pytest.importorskip("scipy.fft", reason="requires scipy") | |
| require_scipy_fft() | |
| sp_fft = pytest.importorskip("scipy.fft", reason="requires scipy") |
| * `irfft` with `out=` now writes directly into `out` when the cast or zero-padded copy of a non-contiguous input has the same memory order as `out`, avoiding a temporary array and an extra copy [gh-396](https://github.com/IntelPython/mkl_fft/pull/396) | ||
|
|
||
| ### Fixed | ||
| * Fixed `mkl_fft.interfaces.scipy_fft.rfft2` ignoring a positional `norm` argument by matching SciPy's parameter order |
There was a problem hiding this comment.
CONTRIBUTING.md asks for a [gh-NNN] link, and the PR has its number now:
| * Fixed `mkl_fft.interfaces.scipy_fft.rfft2` ignoring a positional `norm` argument by matching SciPy's parameter order | |
| * Fixed `mkl_fft.interfaces.scipy_fft.rfft2` ignoring a positional `norm` argument by matching SciPy's parameter order [gh-419](https://github.com/IntelPython/mkl_fft/pull/419) |
| assert np.allclose(x, xx, atol=tol, rtol=tol) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("norm", [None, "forward", "backward", "ortho"]) |
There was a problem hiding this comment.
Optional: only "forward" and "ortho" can fail on master. None keeps norm at its default, and "backward" lands in overwrite_x while norm stays at its default, which is backward anyway.
A signature check would also guard the other scipy_fft functions against the same kind of mismatch, not only rfft2. This one fails on master (AssertionError: rfft2) and passes with this PR; it needs import inspect:
def test_scipy_fft_signatures_match_scipy():
require_scipy_fft()
sp_fft = pytest.importorskip("scipy.fft", reason="requires scipy")
for name in mfi.scipy_fft.__all__:
if not hasattr(sp_fft, name):
continue
expected = inspect.signature(getattr(sp_fft, name))
assert inspect.signature(getattr(mfi.scipy_fft, name)) == expected, name
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 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).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. (Entry added under### Fixed; the link will be added once this PR has a number.)ChipLab's AI agents
Nathan Chandrasekar