irfft#
-
nvmath.
fft. irfft( - operand,
- axes: Sequence[int] | None = None,
- options: FFTOptions | None = None,
- execution: ExecutionCPU | ExecutionCUDA | None = None,
- prolog: DeviceCallable | None = None,
- epilog: DeviceCallable | None = None,
- stream: AnyStream | None = None,
Perform an N-D complex-to-real (C2R) FFT on the provided complex operand. The direction is implicitly inverse.
- Parameters:
operand – A tensor (ndarray-like object). The currently supported types are
numpy.ndarray,cupy.ndarray, andtorch.Tensor.axes – The dimensions along which the FFT is performed.
axes[-1]is the ‘last transformed’ axis for rffts. Currently, it is required that the axes are contiguous and include the first or the last dimension. Only up to 3D FFTs are supported.options – Specify options for the FFT as a
FFTOptionsobject. Alternatively, adictcontaining the parameters for theFFTOptionsconstructor can also be provided. If not specified, the value will be set to the default-constructedFFTOptionsobject.execution – Specify execution space options for the FFT as a
ExecutionCUDAorExecutionCPUobject. Alternatively, a string (‘cuda’ or ‘cpu’), or adictwith the ‘name’ key set to ‘cpu’ or ‘cuda’ and optional parameters relevant to the given execution space. If not specified, the execution space will be selected to match operand’s storage (in GPU or host memory), and the correspondingExecutionCUDAorExecutionCPUobject will be default-constructed.prolog – Provide device-callable function in LTO-IR format to use as load-callback as an object of type
DeviceCallable. Alternatively, adictcontaining the parameters for theDeviceCallableconstructor can also be provided. The default is no prolog. Currently, callbacks are supported only with CUDA execution.epilog – Provide device-callable function in LTO-IR format to use as store-callback as an object of type
DeviceCallable. Alternatively, adictcontaining the parameters for theDeviceCallableconstructor can also be provided. The default is no epilog. Currently, callbacks are supported only with CUDA execution.stream – Provide the CUDA stream to use for executing the operation. Acceptable inputs include
cudaStream_t(as Pythonint),cupy.cuda.Stream, andtorch.cuda.Stream. If a stream is not provided, the current stream from the operand package will be used.
- Returns:
A real tensor that remains on the same device and belongs to the same package as the input operand. The extent of the last transformed axis in the result will be
(operand.shape[axes[-1]] - 1) * 2ifFFTOptions.last_axis_parityiseven, oroperand.shape[axes[-1]] * 2 - 1ifFFTOptions.last_axis_parityisodd.
Examples
>>> import cupy as cp >>> import nvmath
Create a 3-D symmetric complex128 ndarray on the GPU:
>>> shape = 512, 768, 256 >>> a = nvmath.fft.rfft(cp.random.rand(*shape, dtype=cp.float64))
Perform a 3-D C2R FFT using the
irfft()wrapper. The resultris a CuPy float64 ndarray:>>> r = nvmath.fft.irfft(a) >>> r.dtype dtype('float64')
Notes
This function performs an inverse C2R N-D FFT, which is similar to
irfftnbut different fromirfftin various numerical packages.This function is a convenience wrapper around
FFTand and is specifically meant for single use. The same computation can be performed with the stateful API by settingFFTOptions.fft_typeto'C2R'and passing the argumentdirection='inverse'when callingFFT.execute().The input to this function must be Hermitian-symmetric, otherwise the result is undefined. While the symmetry requirement is partially captured by the different extents in the last transformed dimension between the input and result, there are additional constraints. As a specific example, 1-D transforms require the first element (and the last element, if the extent is even) of the input to be purely real-valued. In addition, if the input to
irfftwas generated using an R2C FFT with an odd last axis size,FFTOptions.last_axis_paritymust be set tooddto recover the original signal.For more details, please refer to C2R example and odd C2R example.