CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyfftw

A pythonic wrapper around FFTW, the FFT library, presenting a unified interface for all the supported transforms.

Pending
Overview
Eval results
Files

core-fftw.mddocs/

Core FFTW Interface

Direct access to FFTW functionality through the main FFTW class, providing maximum control over transform planning, execution, and memory management. This interface offers the best performance for repeated transforms and allows fine-grained control over FFTW's advanced features.

Capabilities

FFTW Class

The core class that wraps FFTW plans and provides the primary interface to FFTW functionality.

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
    ):
        """
        Create an FFTW object that performs FFT on the given arrays.
        
        Parameters:
        - input_array: Input array for the transform
        - output_array: Output array for the transform  
        - axes: Axes over which to perform the transform
        - direction: 'FFTW_FORWARD' or 'FFTW_BACKWARD' 
        - flags: FFTW planner flags tuple (e.g., ('FFTW_MEASURE',))
        - threads: Number of threads to use
        - planning_timelimit: Time limit for planning in seconds
        - normalise_idft: Whether to normalize inverse DFT
        - ortho: Whether to use orthogonal normalization
        """
        
    def __call__(
        self, 
        input_array=None, 
        output_array=None, 
        normalise_idft=None, 
        ortho=None
    ):
        """
        Execute the transform, optionally with different arrays.
        
        Parameters:
        - input_array: Input array (uses internal if None)
        - output_array: Output array (uses internal if None)  
        - normalise_idft: Whether to normalize inverse DFT (None uses default)
        - ortho: Whether to use orthogonal normalization (None uses default)
        
        Returns:
        - The output array
        """
    
    def update_arrays(self, new_input_array, new_output_array):
        """
        Update the arrays used by the FFTW object.
        
        Parameters:
        - new_input_array: New input array
        - new_output_array: New output array
        """
    
    def execute(self):
        """
        Execute the transform using the internal arrays.
        """
    
    # Properties
    @property
    def input_array(self):
        """Get the internal input array."""
    
    @property  
    def output_array(self):
        """Get the internal output array."""
    
    @property
    def input_strides(self):
        """Get input array strides."""
    
    @property
    def output_strides(self):
        """Get output array strides."""
    
    @property
    def input_shape(self):
        """Get input array shape."""
    
    @property
    def output_shape(self):
        """Get output array shape."""
    
    @property
    def input_dtype(self):
        """Get input array dtype."""
    
    @property
    def output_dtype(self):
        """Get output array dtype."""
    
    @property
    def direction(self):
        """Get transform direction."""
    
    @property
    def flags_used(self):
        """Get FFTW flags used."""
    
    @property
    def input_alignment(self):
        """Get input array alignment."""
    
    @property
    def output_alignment(self):
        """Get output array alignment."""
    
    @property
    def simd_aligned(self):
        """Check if arrays are SIMD aligned."""
    
    @property
    def N(self):
        """Get transform size."""

Direction Constants

# Transform directions
FFTW_FORWARD: str = 'FFTW_FORWARD'
FFTW_BACKWARD: str = 'FFTW_BACKWARD'

Planning Flags

Available FFTW planner flags for controlling planning effort and behavior:

# Planning effort flags (in order of increasing planning time)
FFTW_ESTIMATE: str = 'FFTW_ESTIMATE'      # Minimal planning
FFTW_MEASURE: str = 'FFTW_MEASURE'        # Default planning
FFTW_PATIENT: str = 'FFTW_PATIENT'        # More thorough planning
FFTW_EXHAUSTIVE: str = 'FFTW_EXHAUSTIVE'  # Most thorough planning

# Algorithm restriction flags
FFTW_DESTROY_INPUT: str = 'FFTW_DESTROY_INPUT'  # Allow input to be destroyed
FFTW_UNALIGNED: str = 'FFTW_UNALIGNED'          # Don't assume alignment
FFTW_CONSERVE_MEMORY: str = 'FFTW_CONSERVE_MEMORY'  # Use less memory

Usage Examples

Basic 1D Transform

import numpy as np
import pyfftw

# Create aligned arrays
N = 1024
a = pyfftw.empty_aligned(N, dtype='complex128')
b = pyfftw.empty_aligned(N, dtype='complex128')

# Fill with data
a[:] = np.random.randn(N) + 1j * np.random.randn(N)

# Create FFTW object
fft_object = pyfftw.FFTW(a, b, direction='FFTW_FORWARD')

# Execute transform
result = fft_object()

2D Transform with Custom Planning

import numpy as np
import pyfftw

# Create 2D arrays
shape = (512, 256)
a = pyfftw.empty_aligned(shape, dtype='complex128')
b = pyfftw.empty_aligned(shape, dtype='complex128')

# Fill with data
a[:] = np.random.randn(*shape) + 1j * np.random.randn(*shape)

# Create FFTW object with patient planning and multiple threads
fft_object = pyfftw.FFTW(
    a, b, 
    axes=(0, 1),
    direction='FFTW_FORWARD',
    flags=('FFTW_PATIENT',),
    threads=4
)

# Execute transform
result = fft_object()

Reusing FFTW Objects

import numpy as np
import pyfftw

# Create arrays
N = 1024
a = pyfftw.empty_aligned(N, dtype='complex128')
b = pyfftw.empty_aligned(N, dtype='complex128')

# Create FFTW object once
fft_object = pyfftw.FFTW(a, b)

# Use multiple times with different data
for i in range(10):
    # Fill with new data
    a[:] = np.random.randn(N) + 1j * np.random.randn(N)
    
    # Execute (reuses existing plan)
    result = fft_object()
    
    # Process result...

Real-to-Complex Transform

import numpy as np
import pyfftw

# Create real input and complex output arrays
N = 1024
real_input = pyfftw.empty_aligned(N, dtype='float64')
complex_output = pyfftw.empty_aligned(N//2 + 1, dtype='complex128')

# Fill with real data
real_input[:] = np.random.randn(N)

# Create FFTW object for real-to-complex transform
fft_object = pyfftw.FFTW(real_input, complex_output)

# Execute transform
result = fft_object()

Install with Tessl CLI

npx tessl i tessl/pypi-pyfftw

docs

configuration-utilities.md

core-fftw.md

fft-builders.md

index.md

interfaces-cache.md

memory-management.md

numpy-fft-interface.md

scipy-fft-interface.md

scipy-fftpack-interface.md

wisdom-management.md

tile.json