Skip to content

2.4.0

Latest

Choose a tag to compare

@vlad-perevezentsev vlad-perevezentsev released this 19 Oct 10:26
· 41 commits to master since this release
cdafe6e

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 importing mkl_fft no longer re-enables the GIL. The free-threaded configuration is built and tested in CI on 3.14t.
  • The python-gil constraint is gone from the conda recipes, which previously pinned mkl_fft to GIL-enabled Python 3.14 builds.

🐍 Python 3.15 Support

  • Added support for Python 3.15. Note that the scipy_interface and test extras cannot be installed from PyPI on 3.15 yet, because mkl-service publishes neither a 3.15 wheel nor an sdist there; conda packages are unaffected.

🧮 Correct norm Scaling for Partial N-D Transforms

  • norm="forward"/"ortho" in fftn, ifftn, rfftn, irfftn and the fft2 family scaled by the full array shape instead of by the transformed axes, so results were wrong whenever axes or s covered only part of the array.
  • irfftn and irfft2 normalized over the input length n instead of the complex-to-real output length 2 * (n - 1).

🎯 out= Correctness

  • fft, ifft and the fftn/fft2 family silently returned out unmodified when the input dtype was not float32, float64, complex64 or complex128.
  • fft/ifft, ifft/ifftn of real input, and rfft/rfftn of cast input produced wrong results, and could write outside of out, when out was non-contiguous or Fortran-ordered.

⚡ Performance

  • Lower Python-side overhead of norm="forward"/"ortho" scaling.
  • rfft no longer makes a slow reordering copy of Fortran-ordered input that needs a cast.
  • One fewer full-array copy in the scipy_fft hfft/hfftn adapters, and the GIL is released during the final conjugation of 1-D ifft of real input.

⚠️ Behavior Changes

  • Out-of-memory failures reported by MKL (DFTI_MEMORY_ERROR) now raise MemoryError instead of ValueError. Code catching ValueError around large transforms will no longer catch them.
  • For Fortran-contiguous input of a dtype other than float32/float64, the result of rfft, rfft2, rfftn and of their numpy_fft/scipy_fft counterparts is now Fortran- rather than C-contiguous.

📦 Build Requirement Changes

  • The minimum build-time Cython requirement is raised to 3.1.0, the first release providing the freethreading_compatible directive.

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_interface and test extras cannot be installed from PyPI on 3.15 yet, because mkl-service publishes neither a 3.15 wheel nor an sdist there

Changed

  • Raised the minimum build-time Cython requirement to 3.1.0, the first release providing the freethreading_compatible directive gh-357
  • Removed the python-gil constraint from the conda recipes, which pinned mkl_fft to GIL-enabled Python 3.14 builds gh-357
  • Out-of-memory failures reported by MKL (DFTI_MEMORY_ERROR) are now raised as MemoryError instead of ValueError gh-373
  • Removed a redundant full-array copy in the hfft and hfftn adapters of mkl_fft.interfaces.scipy_fft gh-382
  • Reduced Python overhead in norm="forward"/"ortho" scaling by computing the scale factor without numpy.prod gh-384
  • rfft now casts input of dtypes other than float32/float64 to float64 keeping 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 of rfft, rfft2, rfftn and of their counterparts in the numpy_fft and scipy_fft interfaces 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 ifft of real input, as it already was in the N-D backend gh-389

Fixed

  • Fixed norm="forward"/"ortho" scaling in fftn, ifftn, rfftn, irfftn and the fft2 family 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 in irfftn and irfft2, which normalized over the input length n rather than the complex-to-real output length 2 * (n - 1) gh-370
  • Fixed possible memory leaks when PyMem_Malloc fails, and raise MemoryError gh-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, ifftn and the fft2 family 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 the fftn/fft2 family returning out unmodified when out is given and the input dtype is not float32, float64, complex64 or complex128 (e.g. integer, bool, float16) gh-387
  • Fixed wrong results and writes outside of out in fft/ifft when the input is cast or zero-padded into a contiguous copy while out has the same non-contiguous layout as the original input gh-387
  • Fixed wrong results and writes outside of out in ifft and ifftn of real input when out is not contiguous: the final complex conjugation treated out as one contiguous block gh-389
  • Fixed wrong results in rfft and rfftn with out for input that is cast to float64 (e.g. integer, float16) when the input and out are Fortran-ordered gh-389

Contributors

Full Changelog: 2.3.2...2.4.0