{"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.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pyfftw"],"cli":null},"imports":["from pyfftw import FFTW","import pyfftw.interfaces.numpy_fft as fft","import pyfftw.config","from pyfftw import zeros"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}