A pythonic wrapper around FFTW, the FFT library, presenting a unified interface for all the supported transforms.
npx @tessl/cli install tessl/pypi-pyfftw@0.15.0A pythonic wrapper around FFTW 3, the high-performance FFT library. pyFFTW provides both complex DFT and real DFT support on arbitrary axes of arbitrary shaped and strided arrays, making it nearly feature-equivalent to numpy.fft while offering significantly better performance and additional precision support.
pip install pyfftwimport pyfftwFor direct access to the FFTW class and utilities:
from pyfftw import FFTW, empty_aligned, zeros_aligned, ones_alignedFor numpy-like interfaces:
from pyfftw.interfaces import numpy_fft
from pyfftw.interfaces import scipy_fftimport pyfftw
import numpy as np
# Create aligned arrays for optimal performance
a = pyfftw.empty_aligned((128, 64), dtype='complex128')
b = pyfftw.empty_aligned((128, 64), dtype='complex128')
# Fill with sample data
a[:] = np.random.randn(128, 64) + 1j * np.random.randn(128, 64)
# Create FFTW object for 2D FFT
fft_object = pyfftw.FFTW(a, b, axes=(0, 1), direction='FFTW_FORWARD')
# Execute the transform
result = fft_object()
# Or use numpy-like interface for simpler usage
from pyfftw.interfaces import numpy_fft
result = numpy_fft.fft2(a)pyFFTW is organized around several key components:
This architecture enables both high-performance direct usage and seamless integration with existing code using numpy/scipy FFT functions.
Direct access to FFTW functionality through the main FFTW class, providing maximum control over transform planning, execution, and memory management.
class FFTW:
def __init__(self, input_array, output_array, axes=(-1,), direction='FFTW_FORWARD', flags=('FFTW_MEASURE',), threads=1, planning_timelimit=None, normalise_idft=True, ortho=False): ...
def __call__(self, input_array=None, output_array=None, normalise_idft=None, ortho=None): ...
def update_arrays(self, new_input_array, new_output_array): ...
def execute(self): ...Utilities for creating and managing aligned arrays to maximize SIMD performance, plus functions for checking alignment and converting existing arrays.
def empty_aligned(shape, dtype='float64', order='C', n=None): ...
def zeros_aligned(shape, dtype='float64', order='C', n=None): ...
def ones_aligned(shape, dtype='float64', order='C', n=None): ...
def n_byte_align(array, n, dtype=None): ...
def byte_align(array, n=None, dtype=None): ...
def is_byte_aligned(array, n=None): ...High-level functions that create FFTW objects with numpy-like signatures, supporting complex and real transforms in 1D, 2D, and N-D variants.
def fft(a, n=None, axis=-1, overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...
def ifft(a, n=None, axis=-1, overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...
def rfft(a, n=None, axis=-1, overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...
def fft2(a, s=None, axes=(-2,-1), overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...
def fftn(a, s=None, axes=None, overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...Drop-in replacement for numpy.fft functions with additional optimization parameters, enabling existing code to benefit from FFTW performance with minimal changes.
def fft(a, n=None, axis=-1, norm=None, overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...
def fft2(a, s=None, axes=(-2,-1), norm=None, overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...
def rfft(a, n=None, axis=-1, norm=None, overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...
def hfft(a, n=None, axis=-1, norm=None, overwrite_input=False, planner_effort='FFTW_ESTIMATE', threads=1): ...Compatible interface for scipy.fft functions with FFTW backend, supporting the newer scipy FFT API including workers parameter and context manager compatibility.
def fft(x, n=None, axis=-1, norm=None, overwrite_x=False, workers=None, plan=None): ...
def fft2(x, s=None, axes=(-2,-1), norm=None, overwrite_x=False, workers=None, plan=None): ...
def next_fast_len(target, real=False): ...Drop-in replacement for scipy.fftpack functions with FFTW backend, including support for discrete cosine and sine transforms. This interface provides backward compatibility with legacy scipy.fftpack code.
def fft(x, n=None, axis=-1, overwrite_x=False, planner_effort=None, threads=None): ...
def dct(x, type=2, n=None, axis=-1, norm=None, overwrite_x=False, planner_effort=None, threads=None): ...
def dst(x, type=2, n=None, axis=-1, norm=None, overwrite_x=False, planner_effort=None, threads=None): ...
def dctn(x, type=2, shape=None, axes=None, norm=None, overwrite_x=False, planner_effort=None, threads=None): ...Functions for importing, exporting, and managing FFTW wisdom to optimize transform planning across sessions and applications.
def export_wisdom(): ...
def import_wisdom(wisdom): ...
def forget_wisdom(): ...Global configuration settings, utility functions for finding optimal transform sizes, and system information access.
def next_fast_len(target): ...
# Configuration constants
simd_alignment: int
NUM_THREADS: int
PLANNER_EFFORT: strCaching system for interface functions that stores FFTW objects to eliminate repeated planning overhead, providing significant performance improvements for repeated transforms.
def enable(): ...
def disable(): ...
def is_enabled(): ...
def set_keepalive_time(keepalive_time): ...