Discrete Fourier Transform (cupy.fft)#

Standard FFTs#

fft(a[, n, axis, norm])

Compute the one-dimensional FFT.

ifft(a[, n, axis, norm])

Compute the one-dimensional inverse FFT.

fft2(a[, s, axes, norm])

Compute the two-dimensional FFT.

ifft2(a[, s, axes, norm])

Compute the two-dimensional inverse FFT.

fftn(a[, s, axes, norm])

Compute the N-dimensional FFT.

ifftn(a[, s, axes, norm])

Compute the N-dimensional inverse FFT.

Real FFTs#

rfft(a[, n, axis, norm])

Compute the one-dimensional FFT for real input.

irfft(a[, n, axis, norm])

Compute the one-dimensional inverse FFT for real input.

rfft2(a[, s, axes, norm])

Compute the two-dimensional FFT for real input.

irfft2(a[, s, axes, norm])

Compute the two-dimensional inverse FFT for real input.

rfftn(a[, s, axes, norm])

Compute the N-dimensional FFT for real input.

irfftn(a[, s, axes, norm])

Compute the N-dimensional inverse FFT for real input.

Hermitian FFTs#

hfft(a[, n, axis, norm])

Compute the FFT of a signal that has Hermitian symmetry.

ihfft(a[, n, axis, norm])

Compute the FFT of a signal that has Hermitian symmetry.

Helper routines#

fftfreq(n[, d])

Return the FFT sample frequencies.

rfftfreq(n[, d])

Return the FFT sample frequencies for real input.

fftshift(x[, axes])

Shift the zero-frequency component to the center of the spectrum.

ifftshift(x[, axes])

The inverse of fftshift().

CuPy-specific APIs#

See the description below for details.


A context manager for setting up load and/or store callbacks.


Set the GPUs to be used in multi-GPU FFT.


Get the per-thread, per-device plan cache, or create one if not found.


Show all of the plan caches' info on this thread.


The default normalization (norm is "backward" or None) has the direct transforms unscaled and the inverse transforms scaled by \(1/n\). If the keyword argument norm is "forward", it is the exact opposite of "backward": the direct transforms are scaled by \(1/n\) and the inverse transforms are unscaled. Finally, if the keyword argument norm is "ortho", both transforms are scaled by \(1/\sqrt{n}\).

Code compatibility features#

FFT functions of NumPy always return numpy.ndarray which type is numpy.complex128 or numpy.float64. CuPy functions do not follow the behavior, they will return numpy.complex64 or numpy.float32 if the type of the input is numpy.float16, numpy.float32, or numpy.complex64.

Internally, cupy.fft always generates a cuFFT plan (see the cuFFT documentation for detail) corresponding to the desired transform. When possible, an n-dimensional plan will be used, as opposed to applying separate 1D plans for each axis to be transformed. Using n-dimensional planning can provide better performance for multidimensional transforms, but requires more GPU memory than separable 1D planning. The user can disable n-dimensional planning by setting cupy.fft.config.enable_nd_planning = False. This ability to adjust the planning type is a deviation from the NumPy API, which does not use precomputed FFT plans.

Moreover, the automatic plan generation can be suppressed by using an existing plan returned by cupyx.scipy.fftpack.get_fft_plan() as a context manager. This is again a deviation from NumPy.

Finally, when using the high-level NumPy-like FFT APIs as listed above, internally the cuFFT plans are cached for possible reuse. The plan cache can be retrieved by get_plan_cache(), and its current status can be queried by show_plan_cache_info(). For finer control of the plan cache, see PlanCache.

Multi-GPU FFT#

cupy.fft can use multiple GPUs. To enable (disable) this feature, set cupy.fft.config.use_multi_gpus to True (False). Next, to set the number of GPUs or the participating GPU IDs, use the function cupy.fft.config.set_cufft_gpus(). All of the limitations listed in the cuFFT documentation apply here. In particular, using more than one GPU does not guarantee better performance.