nvmath.fft.fft — NVIDIA nvmath-python (original) (raw)

nvmath.fft.fft(

x,

*,

axes=None,

direction=None,

options=None,

execution=None,

prolog=None,

epilog=None,

stream=None,

check_dtype=None,

)[source]#

fft(operand, axes=None, direction=None, options=None, execution=None, prolog=None, epilog=None, stream=None)

Perform an N-D complex-to-complex (C2C) FFT on the provided complex operand.

Parameters:

Returns:

A transformed operand that retains the same data type and shape as the input. It remains on the same device and uses the same package as the input operand.

Examples

import cupy as cp import nvmath

Create a 3-D complex128 ndarray on the GPU:

shape = 256, 256, 256 a = cp.random.rand(*shape, dtype=cp.float64) + 1j * cp.random.rand( ... *shape, dtype=cp.float64 ... )

Perform a 3-D C2C FFT using fft(). The result r is also a CuPy complex128 ndarray:

r = nvmath.fft.fft(a)

User may also perform FFT along a subset of dimensions, e.g, 2-D C2C FFT along the first two dimensions, batched along the last dimension:

axes = 0, 1 r = nvmath.fft.fft(a, axes=axes)

For C2C type FFT operation, the output can be directly computed inplace thus overwriting the input operand. This can be specified using options to the FFT:

o = nvmath.fft.FFTOptions(inplace=True) r = nvmath.fft.fft(a, options=o) r is a True

See FFTOptions for the complete list of available options.

The package current stream is used by default, but a stream can be explicitly provided to the FFT operation. This can be done if the FFT operand is computed on a different stream, for example:

s = cp.cuda.Stream() with s: ... a = cp.random.rand(*shape) + 1j * cp.random.rand(*shape) r = nvmath.fft.fft(a, stream=s)

The operation above runs on stream s and is ordered with respect to the input computation.

Create a NumPy ndarray on the CPU.

import numpy as np b = np.random.rand(*shape) + 1j * np.random.rand(*shape)

Provide the NumPy ndarray to fft(), with the result also being a NumPy ndarray:

r = nvmath.fft.fft(b)

Notes

Further examples can be found in the nvmath/examples/fft directory.