Repository navigation
Overview
The release enables free-threaded (GIL-disabled) CPython builds and adds support for Python 3.15. It also fixes a group of long-standing correctness bugs: norm="forward" and norm="ortho" scaling was wrong whenever an N-D transform covered only a subset of
axes, and transforms writing into a user-provided out array produced wrong results — or wrote past the end of out — for non-contiguous out, for Fortran-ordered input, and for input of dtypes that have to be cast. Several memory leaks and unchecked backend statuses in the C layer are fixed as well. Building from source now requires a newer Cython.
Highlights
🧵 Free-Threaded CPython
- The Cython extension is compiled with
freethreading_compatible=True, so importingmkl_fftno longer re-enables the GIL. The free-threaded configuration is built and tested in CI on 3.14t. - The
python-gilconstraint is gone from the conda recipes, which previously pinnedmkl_fftto GIL-enabled Python 3.14 builds.
🐍 Python 3.15 Support
- Added support for Python 3.15. Note that the
scipy_interfaceandtestextras cannot be installed from PyPI on 3.15 yet, becausemkl-servicepublishes neither a 3.15 wheel nor an sdist there; conda packages are unaffected.
🧮 Correct norm Scaling for Partial N-D Transforms
norm="forward"/"ortho"infftn,ifftn,rfftn,irfftnand thefft2family scaled by the full array shape instead of by the transformed axes, so results were wrong wheneveraxesorscovered only part of the array.irfftnandirfft2normalized over the input lengthninstead of the complex-to-real output length2 * (n - 1).
🎯 out= Correctness
fft,ifftand thefftn/fft2family silently returnedoutunmodified when the input dtype was notfloat32,float64,complex64orcomplex128.fft/ifft,ifft/ifftnof real input, andrfft/rfftnof cast input produced wrong results, and could write outside ofout, whenoutwas non-contiguous or Fortran-ordered.
⚡ Performance
- Lower Python-side overhead of
norm="forward"/"ortho"scaling. rfftno longer makes a slow reordering copy of Fortran-ordered input that needs a cast.- One fewer full-array copy in the
scipy_ffthfft/hfftnadapters, and the GIL is released during the final conjugation of 1-Difftof real input.
- Out-of-memory failures reported by MKL (
DFTI_MEMORY_ERROR) now raiseMemoryErrorinstead ofValueError. Code catchingValueErroraround large transforms will no longer catch them. - For Fortran-contiguous input of a dtype other than
float32/float64, the result ofrfft,rfft2,rfftnand of theirnumpy_fft/scipy_fftcounterparts is now Fortran- rather than C-contiguous.
📦 Build Requirement Changes
- The minimum build-time
Cythonrequirement is raised to3.1.0, the first release providing thefreethreading_compatibledirective.
Python Version Support
- ✅ Python 3.10, 3.11, 3.12, 3.13, 3.14, 3.15 (plus free-threaded 3.14t)
Detailed Changes
Added
- Added support for free-threaded (GIL-disabled) CPython builds: the Cython extension is compiled with
freethreading_compatible=True; the free-threaded configuration is built and tested in CI on 3.14t gh-357 - Enabled support of Python 3.15 gh-378. The
scipy_interfaceandtestextras cannot be installed from PyPI on 3.15 yet, becausemkl-servicepublishes neither a 3.15 wheel nor an sdist there
Changed
- Raised the minimum build-time
Cythonrequirement to3.1.0, the first release providing thefreethreading_compatibledirective gh-357 - Removed the
python-gilconstraint from the conda recipes, which pinnedmkl_fftto GIL-enabled Python 3.14 builds gh-357 - Out-of-memory failures reported by MKL (
DFTI_MEMORY_ERROR) are now raised asMemoryErrorinstead ofValueErrorgh-373 - Removed a redundant full-array copy in the
hfftandhfftnadapters ofmkl_fft.interfaces.scipy_fftgh-382 - Reduced Python overhead in
norm="forward"/"ortho"scaling by computing the scale factor withoutnumpy.prodgh-384 rfftnow casts input of dtypes other thanfloat32/float64tofloat64keeping its memory order instead of making it C-contiguous, avoiding a slow reordering copy for Fortran-ordered input gh-389- For Fortran-contiguous input of a dtype other than
float32/float64, the result ofrfft,rfft2,rfftnand of their counterparts in thenumpy_fftandscipy_fftinterfaces is now Fortran- rather than C-contiguous: the output order follows the input, Fortran for Fortran-contiguous input and C otherwise gh-389 - The GIL is now released during the final conjugation of 1-D
ifftof real input, as it already was in the N-D backend gh-389
Fixed
- Fixed
norm="forward"/"ortho"scaling infftn,ifftn,rfftn,irfftnand thefft2family when only a subset of axes is transformed: the scale used the full array shape instead of the transformed axes gh-336, gh-370 - Fixed
norm="forward"/"ortho"scaling inirfftnandirfft2, which normalized over the input lengthnrather than the complex-to-real output length2 * (n - 1)gh-370 - Fixed possible memory leaks when
PyMem_Mallocfails, and raiseMemoryErrorgh-373 - Fixed possible memory leaks when multi-iterator constructors fail gh-373
- Fixed N-D transforms returning a success status when a scratch allocation fails gh-373
- Fixed
fftn,ifftnand thefft2family returning an uncomputed result instead of raising when MKL reports an error for a transform over all axes: the status of the N-D backend call was never checked gh-373 - Fixed
fft,ifft, and thefftn/fft2family returningoutunmodified whenoutis given and the input dtype is notfloat32,float64,complex64orcomplex128(e.g. integer,bool,float16) gh-387 - Fixed wrong results and writes outside of
outinfft/ifftwhen the input is cast or zero-padded into a contiguous copy whileouthas the same non-contiguous layout as the original input gh-387 - Fixed wrong results and writes outside of
outinifftandifftnof real input whenoutis not contiguous: the final complex conjugation treatedoutas one contiguous block gh-389 - Fixed wrong results in
rfftandrfftnwithoutfor input that is cast tofloat64(e.g. integer,float16) when the input andoutare Fortran-ordered gh-389
Contributors
- Anton Volkov (@antonwolfy)
- Jordan Harlow (@jharlow-intel)
- Nikita Grigorian (@ndgrigorian)
- Venkata Sai Gireesh Chamarthi (@vchamarthi)
- Vladislav Perevezentsev (@vlad-perevezentsev)
Full Changelog: 2.3.2...2.4.0