Skip to content

Commit 6c5f6b5

Browse files
committed
Add docstring to _iter_complementary
1 parent d87fc0b commit 6c5f6b5

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

mkl_fft/_fft_utils.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,67 @@ def _init_nd_shape_and_axes(x, shape, axes):
209209

210210

211211
def _iter_complementary(x, axes, func, kwargs, result):
212+
"""
213+
Apply FFT function by iterating over complementary axes.
214+
215+
This function applies an FFT operation to slices of the input array
216+
by iterating over all axes that are NOT in the `axes` parameter
217+
(the complementary axes). For each position in the complementary axes,
218+
it applies the FFT function to a slice along the specified axes.
219+
220+
Parameters
221+
----------
222+
x : ndarray
223+
Input array.
224+
axes : int, sequence of ints, or None
225+
Axes along which to perform the FFT operation. The function iterates
226+
over the complementary axes (axes not in this parameter). If ``None``,
227+
performs direct N-D FFT without iteration.
228+
Default: None
229+
func : callable
230+
FFT function to apply to each slice. Should accept array input and
231+
return transformed output.
232+
kwargs : dict
233+
Additional keyword arguments to pass to `func`.
234+
result : ndarray
235+
Pre-allocated output array where results are stored.
236+
237+
Returns
238+
-------
239+
ndarray
240+
The transformed array (same as `result`).
241+
242+
Notes
243+
-----
244+
For complex input, the function uses in-place operations with the `out`
245+
parameter passed for better performance. For real input, `np.copyto` is
246+
used instead to avoid element ordering issues that can occur with the
247+
`out` parameter in certain FFT operations.
248+
249+
Examples
250+
--------
251+
Consider an input array with shape (3, 4, 5) and performing FFT
252+
along axis 2 only:
253+
254+
>>> x = np.random.random((3, 4, 5))
255+
>>> result = np.empty((3, 4, 5), dtype=np.complex128)
256+
>>> _iter_complementary(
257+
... x, axes=(2,), func=_direct_fftnd,
258+
... kwargs={'direction': 1, 'fsc': 1.0}, result=result
259+
... )
260+
261+
The function will iterate over axes 0 and 1 (complementary axes)
262+
and apply `_direct_fftnd` to each 1-D slice along axis 2:
263+
264+
- Iteration 0: func(x[0, 0, :]) -> result[0, 0, :]
265+
- Iteration 1: func(x[0, 1, :]) -> result[0, 1, :]
266+
- ...
267+
- Iteration 11: func(x[2, 3, :]) -> result[2, 3, :]
268+
269+
Total: 3 * 4 = 12 FFT operations on arrays of shape (5,).
270+
271+
"""
272+
212273
if axes is None:
213274
# s and axes are None, direct N-D FFT
214275
return func(x, **kwargs, out=result)

0 commit comments

Comments
 (0)