or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

configuration-utilities.mdcore-fftw.mdfft-builders.mdindex.mdinterfaces-cache.mdmemory-management.mdnumpy-fft-interface.mdscipy-fft-interface.mdscipy-fftpack-interface.mdwisdom-management.md

core-fftw.mddocs/

0

# Core FFTW Interface

1

2

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.

3

4

## Capabilities

5

6

### FFTW Class

7

8

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

9

10

```python { .api }

11

class FFTW:

12

def __init__(

13

self,

14

input_array,

15

output_array,

16

axes=(-1,),

17

direction='FFTW_FORWARD',

18

flags=('FFTW_MEASURE',),

19

threads=1,

20

planning_timelimit=None,

21

normalise_idft=True,

22

ortho=False

23

):

24

"""

25

Create an FFTW object that performs FFT on the given arrays.

26

27

Parameters:

28

- input_array: Input array for the transform

29

- output_array: Output array for the transform

30

- axes: Axes over which to perform the transform

31

- direction: 'FFTW_FORWARD' or 'FFTW_BACKWARD'

32

- flags: FFTW planner flags tuple (e.g., ('FFTW_MEASURE',))

33

- threads: Number of threads to use

34

- planning_timelimit: Time limit for planning in seconds

35

- normalise_idft: Whether to normalize inverse DFT

36

- ortho: Whether to use orthogonal normalization

37

"""

38

39

def __call__(

40

self,

41

input_array=None,

42

output_array=None,

43

normalise_idft=None,

44

ortho=None

45

):

46

"""

47

Execute the transform, optionally with different arrays.

48

49

Parameters:

50

- input_array: Input array (uses internal if None)

51

- output_array: Output array (uses internal if None)

52

- normalise_idft: Whether to normalize inverse DFT (None uses default)

53

- ortho: Whether to use orthogonal normalization (None uses default)

54

55

Returns:

56

- The output array

57

"""

58

59

def update_arrays(self, new_input_array, new_output_array):

60

"""

61

Update the arrays used by the FFTW object.

62

63

Parameters:

64

- new_input_array: New input array

65

- new_output_array: New output array

66

"""

67

68

def execute(self):

69

"""

70

Execute the transform using the internal arrays.

71

"""

72

73

# Properties

74

@property

75

def input_array(self):

76

"""Get the internal input array."""

77

78

@property

79

def output_array(self):

80

"""Get the internal output array."""

81

82

@property

83

def input_strides(self):

84

"""Get input array strides."""

85

86

@property

87

def output_strides(self):

88

"""Get output array strides."""

89

90

@property

91

def input_shape(self):

92

"""Get input array shape."""

93

94

@property

95

def output_shape(self):

96

"""Get output array shape."""

97

98

@property

99

def input_dtype(self):

100

"""Get input array dtype."""

101

102

@property

103

def output_dtype(self):

104

"""Get output array dtype."""

105

106

@property

107

def direction(self):

108

"""Get transform direction."""

109

110

@property

111

def flags_used(self):

112

"""Get FFTW flags used."""

113

114

@property

115

def input_alignment(self):

116

"""Get input array alignment."""

117

118

@property

119

def output_alignment(self):

120

"""Get output array alignment."""

121

122

@property

123

def simd_aligned(self):

124

"""Check if arrays are SIMD aligned."""

125

126

@property

127

def N(self):

128

"""Get transform size."""

129

```

130

131

### Direction Constants

132

133

```python { .api }

134

# Transform directions

135

FFTW_FORWARD: str = 'FFTW_FORWARD'

136

FFTW_BACKWARD: str = 'FFTW_BACKWARD'

137

```

138

139

### Planning Flags

140

141

Available FFTW planner flags for controlling planning effort and behavior:

142

143

```python { .api }

144

# Planning effort flags (in order of increasing planning time)

145

FFTW_ESTIMATE: str = 'FFTW_ESTIMATE' # Minimal planning

146

FFTW_MEASURE: str = 'FFTW_MEASURE' # Default planning

147

FFTW_PATIENT: str = 'FFTW_PATIENT' # More thorough planning

148

FFTW_EXHAUSTIVE: str = 'FFTW_EXHAUSTIVE' # Most thorough planning

149

150

# Algorithm restriction flags

151

FFTW_DESTROY_INPUT: str = 'FFTW_DESTROY_INPUT' # Allow input to be destroyed

152

FFTW_UNALIGNED: str = 'FFTW_UNALIGNED' # Don't assume alignment

153

FFTW_CONSERVE_MEMORY: str = 'FFTW_CONSERVE_MEMORY' # Use less memory

154

```

155

156

## Usage Examples

157

158

### Basic 1D Transform

159

160

```python

161

import numpy as np

162

import pyfftw

163

164

# Create aligned arrays

165

N = 1024

166

a = pyfftw.empty_aligned(N, dtype='complex128')

167

b = pyfftw.empty_aligned(N, dtype='complex128')

168

169

# Fill with data

170

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

171

172

# Create FFTW object

173

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

174

175

# Execute transform

176

result = fft_object()

177

```

178

179

### 2D Transform with Custom Planning

180

181

```python

182

import numpy as np

183

import pyfftw

184

185

# Create 2D arrays

186

shape = (512, 256)

187

a = pyfftw.empty_aligned(shape, dtype='complex128')

188

b = pyfftw.empty_aligned(shape, dtype='complex128')

189

190

# Fill with data

191

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

192

193

# Create FFTW object with patient planning and multiple threads

194

fft_object = pyfftw.FFTW(

195

a, b,

196

axes=(0, 1),

197

direction='FFTW_FORWARD',

198

flags=('FFTW_PATIENT',),

199

threads=4

200

)

201

202

# Execute transform

203

result = fft_object()

204

```

205

206

### Reusing FFTW Objects

207

208

```python

209

import numpy as np

210

import pyfftw

211

212

# Create arrays

213

N = 1024

214

a = pyfftw.empty_aligned(N, dtype='complex128')

215

b = pyfftw.empty_aligned(N, dtype='complex128')

216

217

# Create FFTW object once

218

fft_object = pyfftw.FFTW(a, b)

219

220

# Use multiple times with different data

221

for i in range(10):

222

# Fill with new data

223

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

224

225

# Execute (reuses existing plan)

226

result = fft_object()

227

228

# Process result...

229

```

230

231

### Real-to-Complex Transform

232

233

```python

234

import numpy as np

235

import pyfftw

236

237

# Create real input and complex output arrays

238

N = 1024

239

real_input = pyfftw.empty_aligned(N, dtype='float64')

240

complex_output = pyfftw.empty_aligned(N//2 + 1, dtype='complex128')

241

242

# Fill with real data

243

real_input[:] = np.random.randn(N)

244

245

# Create FFTW object for real-to-complex transform

246

fft_object = pyfftw.FFTW(real_input, complex_output)

247

248

# Execute transform

249

result = fft_object()

250

```