mkl_fft -- a NumPy-based Python interface to Intel® oneAPI Math Kernel Library (oneMKL) Fourier Transform Functions
Introduction
mkl_fft is part of Intel® Distribution for Python* optimizations to NumPy.
It offers a thin layered python interface to the Intel® oneAPI Math Kernel Library (oneMKL) Fourier Transform Functions that allows efficient access to computing a discrete Fourier transform through the fast Fourier transform (FFT) algorithm. As a result, its performance is close to the performance of native C/Intel® oneMKL. The optimizations are provided for real and complex data types in both single and double precisions for in-place and out-of-place modes of operation. For analyzing the performance use FFT benchmarks.
Thanks to Intel® oneMKL’s flexibility in its supports for arbitrarily strided input and output arrays both one-dimensional and multi-dimensional FFTs along distinct axes can be performed directly, without the need to copy the input into a contiguous array first. Furthermore, input strides can be arbitrary, including negative or zero, as long as strides remain an integer multiple of array’s item size, otherwise a copy will be made.
More details can be found in "Accelerating Scientific Python with Intel Optimizations" from Proceedings of the 16th Python in Science Conference (SciPy 2017).
Installation
mkl_fft can be installed into conda environment from Intel's channel using:
conda install -c https://software.repos.intel.com/python/conda mkl_fft
or from conda-forge channel:
conda install -c conda-forge mkl_fft
To install mkl_fft PyPI package please use the following command:
python -m pip install --index-url https://software.repos.intel.com/python/pypi --extra-index-url https://pypi.org/simple mkl_fft
If command above installs NumPy package from the PyPI, please use following command to install Intel optimized NumPy wheel package from Intel PyPI Cloud:
python -m pip install --index-url https://software.repos.intel.com/python/pypi --extra-index-url https://pypi.org/simple mkl_fft numpy==<numpy_version>
where <numpy_version> should be the latest version from https://software.repos.intel.com/python/conda/.
How to use?
mkl_fft.interfaces module
The recommended way to use mkl_fft package is through mkl_fft.interfaces module. These interfaces act as drop-in replacements for equivalent functions in NumPy and SciPy. Learn more about these interfaces here.
mkl_fft package
While using the interfaces module is the recommended way to leverage mk_fft, one can also use mkl_fft directly with the following FFT functions:
complex-to-complex (c2c) transforms:
fft(x, n=None, axis=-1, norm=None, out=None) - 1D FFT, similar to scipy.fft.fft
fft2(x, s=None, axes=(-2, -1), norm=None, out=None) - 2D FFT, similar to scipy.fft.fft2
fftn(x, s=None, axes=None, norm=None, out=None) - ND FFT, similar to scipy.fft.fftn
and similar inverse FFT (ifft*) functions.
real-to-complex (r2c) and complex-to-real (c2r) transforms:
rfft(x, n=None, axis=-1, norm=None, out=None) - r2c 1D FFT, similar to numpy.fft.rfft
rfft2(x, s=None, axes=(-2, -1), norm=None, out=None) - r2c 2D FFT, similar to numpy.fft.rfft2
rfftn(x, s=None, axes=None, norm=None, out=None) - r2c ND FFT, similar to numpy.fft.rfftn
and similar inverse c2r FFT (irfft*) functions.
The following example shows how to use mkl_fft for calculating a 1D FFT.
import numpy, mkl_fft
a = numpy.random.randn(10) + 1j*numpy.random.randn(10)
mkl_res = mkl_fft.fft(a)
np_res = numpy.fft.fft(a)
numpy.allclose(mkl_res, np_res)
# True
Patching Mechanisms
mkl_fft provides convenient patch methods to enable MKL-accelerated FFT operations in NumPy with or without modifying your code.
CLI Quickstart
Persistent patch (all Python sessions)
# Install
python -m mkl_fft --patch install
# Status (exit code: 0 = installed, 1 = not installed)
python -m mkl_fft --patch status
# Remove
python -m mkl_fft --patch uninstall
Verify current FFT backend
python -c "import numpy; print(f'numpy.fft.fft.__module__: {numpy.fft.fft.__module__}')"
One-shot patch (single command only)
# Script
python -m mkl_fft --with-numpy-patch my_script.py
# Pytest
python -m mkl_fft --with-numpy-patch -m pytest tests/
# One-liner
python -m mkl_fft --with-numpy-patch -c "import numpy; print(f\"numpy.fft.fft.__module__: {numpy.fft.fft.__module__}\")"
# Non-Python command
python -m mkl_fft --with-numpy-patch -- <command> [args...]
Programmatic Quickstart
import mkl_fft
mkl_fft.patch_numpy_fft()
print(mkl_fft.is_patched())
mkl_fft.restore_numpy_fft()
with mkl_fft.mkl_fft():
pass
Building from source
A C compiler, Intel® oneAPI Math Kernel Library (oneMKL), and NumPy are required
to build mkl_fft from source.
Executing
python -m pip install .
will pull in the required build dependencies, including mkl and numpy, and build mkl_fft.
If you already have mkl and numpy installed (from your system or a conda environment)
and want to reuse them instead of pulling fresh copies into an isolated build, first
install the build dependencies:
pip install meson-python cmake ninja cython numpy mkl-devel
then build against the existing installation with:
python -m pip install --no-build-isolation --no-deps .
Optionally, install scipy to use the mkl_fft.interfaces.scipy_fft module:
pip install scipy
Release files for mkl-fft 2.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 1.5 MB
Release files / mkl_fft-2.3.2-0-cp314-cp314-win_amd64.whl
| Download URL | mkl_fft-2.3.2-0-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 137.8 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9ea486a052a1bc4fe955162a01a4c26f8de33552ef979b1943e096a5135756b7
|
|
BLAKE2b-256 checksum How to use checksums |
35264003095bf61e92d979ecf8844acaa178a3cc95aac765e39eae764c40b209
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp314-cp314-manylinux_2_28_x86_64.whl
| Download URL | mkl_fft-2.3.2-0-cp314-cp314-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 152.0 kB |
| Tags | CPython 3.14 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
f3d5c4e9a98e69990c0fded2761c52c76b66bcf0bc9a103aaa48b120dfb1abc0
|
|
BLAKE2b-256 checksum How to use checksums |
5fbf053500231ed5694caa0e171ded5435900830742e866ebca856f5b9521740
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp313-cp313-win_amd64.whl
| Download URL | mkl_fft-2.3.2-0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 137.5 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
eb6f3895142bda817eb5981ed292d5930fca7a94f1c985c3b016bb211b0cafb2
|
|
BLAKE2b-256 checksum How to use checksums |
9db5bb33af0c8d137f46d37c84eea6409b4743df33ab9bdae4942f411ac41ae1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | mkl_fft-2.3.2-0-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 151.5 kB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
09823ae97971b80d2724f3ca2d95928570f4991452869dc024378fe6c5681e27
|
|
BLAKE2b-256 checksum How to use checksums |
e5cd316530dd810d5919a0bf79dde9643241e0dc93ae099ab4ee5516a397c682
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp312-cp312-win_amd64.whl
| Download URL | mkl_fft-2.3.2-0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 137.8 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
76c91d4b861ff6a2f8791d394a7923e147753a7cba7420b59f10959cb114dabe
|
|
BLAKE2b-256 checksum How to use checksums |
4028c934e255a16aac63e79b24f2d2c1b993140a62c94b7e91b087455f935003
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | mkl_fft-2.3.2-0-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 154.2 kB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1333810c755f9478916f3ea00894b36a525d27a1f5f7dce58070a381301b2e8b
|
|
BLAKE2b-256 checksum How to use checksums |
5ba88492610d531360d9a2a76bfac2edfee8791158544415397f6949ffeae3c8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp311-cp311-win_amd64.whl
| Download URL | mkl_fft-2.3.2-0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 139.4 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
8bf20db0eff320af52a5ce6b4270606c8877cbdc6c3b52f8a465a7d5f0151691
|
|
BLAKE2b-256 checksum How to use checksums |
0fad1c381577d53118604b258ebb668660cce663de0bae311103c3e1f8a3f63d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | mkl_fft-2.3.2-0-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 152.6 kB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
9b4092535403139e6af5dfe192efc3129313a4d8237bbe9e2419d8db7f9e3630
|
|
BLAKE2b-256 checksum How to use checksums |
e51c18a7b1db8e149fd60c49089e72bd48f2606103be5caaad984d18495fd891
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp310-cp310-win_amd64.whl
| Download URL | mkl_fft-2.3.2-0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 139.4 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5bc8d97fe4fd2d2a8836f3aad1438dc47fb5616c092e2817a04b1cc6a236a2fa
|
|
BLAKE2b-256 checksum How to use checksums |
7af6f6cf3787180eb60a6c6f62e162e7b0d01e33ce1cd4820373fa5a12241cb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / mkl_fft-2.3.2-0-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | mkl_fft-2.3.2-0-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 152.7 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
5f7e1eecb7f5f2295e216d78da74ef79ea7a3cfc3a3048b6bb44ce5c83a35aca
|
|
BLAKE2b-256 checksum How to use checksums |
c4c795895d0b86b6f028b16d6b92ed9a963c807762bb46652d782192bb39683b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|