{"id":9215,"library":"pyfftw","title":"pyFFTW","description":"pyFFTW is a high-performance Pythonic wrapper around FFTW 3, the highly optimized Fast Fourier Transform C library. It provides a unified interface for various FFT operations, including interfaces compatible with NumPy's `fft` module, SciPy's `fft` module, and Dask's `fft` module. The current version is 0.15.1, with releases typically occurring a few times a year, including significant updates for Python and dependency compatibility.","status":"active","version":"0.15.1","language":"en","source_language":"en","source_url":"https://github.com/pyFFTW/pyFFTW","tags":["scientific computing","fft","fast fourier transform","numpy","scipy","dask","performance"],"install":[{"cmd":"pip install pyfftw","lang":"bash","label":"Install pyFFTW"}],"dependencies":[{"reason":"Essential for array handling and most operations.","package":"numpy","optional":false},{"reason":"Required if using the pyfftw.interfaces.scipy_fft module.","package":"scipy","optional":true},{"reason":"Required if using the pyfftw.interfaces.dask_fft module.","package":"dask","optional":true}],"imports":[{"symbol":"FFTW","correct":"from pyfftw import FFTW"},{"note":"The top-level 'pyfftw' module does not expose 'fft' directly; it must be imported from 'interfaces'.","wrong":"import pyfftw; pyfftw.fft.fft(...)","symbol":"interfaces.numpy_fft","correct":"import pyfftw.interfaces.numpy_fft as fft"},{"symbol":"config","correct":"import pyfftw.config"},{"symbol":"zeros","correct":"from pyfftw import zeros"}],"quickstart":{"code":"import pyfftw\nimport numpy as np\nimport pyfftw.interfaces.numpy_fft as fft\nimport os\n\n# Configure pyFFTW for optimal performance\npyfftw.config.NUM_THREADS = os.cpu_count() or 1 # Use all available CPU cores\npyfftw.config.PLANNER_EFFORT = 'FFTW_ESTIMATE' # 'FFTW_MEASURE' for better, but slower, planning\npyfftw.config.overwrite_input = True # Allow FFTW to overwrite input array for efficiency\n\n# Create a sample NumPy array\ninput_data = np.random.randn(128) + 1j*np.random.randn(128)\n\n# Perform FFT using the numpy_fft interface (drop-in replacement)\noutput_fft = fft.fft(input_data)\n\n# Perform inverse FFT\noutput_ifft = fft.ifft(output_fft)\n\nprint(f\"Original data (first 5): {input_data[:5]})\")\nprint(f\"FFT output (first 5): {output_fft[:5]})\")\nprint(f\"IFFT output (first 5): {output_ifft[:5]})\")\nprint(f\"Difference (should be close to zero): {np.max(np.abs(input_data - output_ifft))}\")\n\n# Example using the direct FFTW class for more control\n# Pre-allocate arrays for in-place transform if desired\na = pyfftw.empty_aligned(128, dtype='complex128')\nb = pyfftw.empty_aligned(128, dtype='complex128')\n\na[:] = input_data # Copy data to aligned array\n\nfft_object = pyfftw.FFTW(a, b, direction='FFTW_FORWARD',\n                          flags=('FFTW_MEASURE',), threads=pyfftw.config.NUM_THREADS,\n                          planning_effort=pyfftw.config.PLANNER_EFFORT)\n\nfft_object()\n\nprint(f\"\\nDirect FFTW class output (first 5): {b[:5]})\")\n","lang":"python","description":"This quickstart demonstrates how to use pyFFTW's `numpy_fft` interface for a drop-in replacement, and also shows the lower-level `pyfftw.FFTW` class for more granular control over the FFT process. It includes configuration for multithreading and planning effort."},"warnings":[{"fix":"Install FFTW3 on your system. For Debian/Ubuntu: `sudo apt-get install libfftw3-dev`. For Fedora: `sudo dnf install fftw-devel`. For macOS: `brew install fftw`. For Windows, refer to the pyFFTW documentation for pre-compiled binaries or build instructions.","message":"The `pyfftw` Python package is a wrapper around the FFTW 3 C library. You MUST have the FFTW 3 C library installed on your system for `pyfftw` to function. `pip install pyfftw` only installs the Python bindings, not the underlying C library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade your Python environment to 3.11 or newer, or pin `pyfftw` to an older compatible version. For Python 3.8-3.10, use `pyfftw<0.15.0`. For Python 3.7, use `pyfftw<0.13.1`. For Python 2.7, use `pyfftw<0.12.0`.","message":"Python 3.7 and 2.7 support has been dropped in recent versions. Specifically, Python 2.7 support ended with v0.11.x (last version to support it was v0.11.1), and Python 3.7 support ended with v0.13.0. Version 0.15.0 and later require Python >= 3.11.","severity":"breaking","affected_versions":">=0.12.0 (for Python 2.7), >=0.13.1 (for Python 3.7), >=0.15.0 (for Python < 3.11)"},{"fix":"Before performing transforms, set `pyfftw.config.PLANNER_EFFORT = 'FFTW_MEASURE'` or `'FFTW_PATIENT'`. For persistent performance, export wisdom after planning: `wisdom = pyfftw.export_wisdom()` and import it on startup: `pyfftw.import_wisdom(wisdom)`.","message":"For optimal performance, especially with repeated transforms of the same size and type, configure `pyfftw.config.PLANNER_EFFORT` and use wisdom files. Setting `PLANNER_EFFORT = 'FFTW_MEASURE'` or `'FFTW_PATIENT'` allows FFTW to find a highly optimized plan (takes longer for the first run). Wisdom files (`pyfftw.export_wisdom()`/`pyfftw.import_wisdom()`) save these plans to disk, avoiding re-planning on subsequent executions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Replace `import pyfftw.interfaces.scipy_fftpack as fft` with `import pyfftw.interfaces.scipy_fft as fft`.","message":"The `pyfftw.interfaces.scipy_fftpack` interface, which mirrored the older `scipy.fftpack` module, is deprecated. Users should migrate to `pyfftw.interfaces.scipy_fft` which aligns with the modern `scipy.fft` module (introduced in SciPy 1.4).","severity":"deprecated","affected_versions":">=0.12.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install pyfftw` to install the package.","cause":"The `pyfftw` Python package has not been installed in the current environment.","error":"ModuleNotFoundError: No module named 'pyfftw'"},{"fix":"Ensure FFTW3 (e.g., `libfftw3-dev` on Debian/Ubuntu, `fftw-devel` on Fedora, `fftw` on Homebrew) is correctly installed on your system and accessible in the system's library path. For Windows, refer to pyFFTW's installation documentation for pre-compiled binaries or build instructions.","cause":"The underlying FFTW C library is either not installed, not correctly linked, or a compatible version could not be found by `pyfftw`.","error":"PyFFTWError: The self-test of the installed FFTW library failed"},{"fix":"Import the desired interface explicitly, for example: `import pyfftw.interfaces.numpy_fft as fft`.","cause":"Attempting to use a top-level `fft` function directly from `pyfftw` without importing one of the specific interface modules (e.g., `numpy_fft`).","error":"AttributeError: module 'pyfftw' has no attribute 'fft'"},{"fix":"Ensure your input array is contiguous. Use `np.ascontiguousarray(my_array)` if necessary, or create the array directly using `pyfftw.empty_aligned`, `pyfftw.zeros`, or `pyfftw.ones` for maximum efficiency.","cause":"FFTW and `pyfftw` perform optimally with contiguous arrays. If you pass a sliced or non-contiguous NumPy array, it might raise this error or force a copy, reducing performance.","error":"ValueError: Input array is not C-contiguous or Fortran-contiguous."}]}