rfft(input, signal_ndim, normalized=False, onesided=True) → Tensor¶
Real-to-complex Discrete Fourier Transform.
torch.rfft()is deprecated and will be removed in a future PyTorch release. Use the new torch.fft module functions, instead, by importing torch.fft and calling
torch.fft.rfft()for one-sided output, or
torch.fft.fft()for two-sided output.
This method computes the real-to-complex discrete Fourier transform. It is mathematically equivalent with
fft()with differences only in formats of the input and output.
This method supports 1D, 2D and 3D real-to-complex transforms, indicated by
inputmust be a tensor with at least
signal_ndimdimensions with optionally arbitrary number of leading batch dimensions. If
normalizedis set to
True, this normalizes the result by dividing it with so that the operator is unitary, where is the size of signal dimension .
The real-to-complex Fourier transform results follow conjugate symmetry:
where the index arithmetic is computed modulus the size of the corresponding dimension, is the conjugate operator, and =
onesidedflag controls whether to avoid redundancy in the output results. If set to
True(default), the output will not be full complex result of shape , where is the shape of
input, but instead the last dimension will be halfed as of size .
The inverse of this function is
For CUDA tensors, an LRU cache is used for cuFFT plans to speed up repeatedly running FFT methods on tensors of same geometry with same configuration. See cuFFT plan cache for more details on how to monitor and control the cache.
Due to limited dynamic range of half datatype, performing this operation in half precision may cause the first element of result to overflow for certain inputs.
For CPU tensors, this method is currently only available with MKL. Use
torch.backends.mkl.is_available()to check if MKL is installed.
input (Tensor) – the input tensor of at least
signal_ndim (int) – the number of dimensions in each signal.
signal_ndimcan only be 1, 2 or 3
normalized (bool, optional) – controls whether to return normalized results. Default:
onesided (bool, optional) – controls whether to return half of results to avoid redundancy. Default:
A tensor containing the real-to-complex Fourier transform result
- Return type
>>> x = torch.randn(5, 5) >>> torch.rfft(x, 2).shape torch.Size([5, 3, 2]) >>> torch.rfft(x, 2, onesided=False).shape torch.Size([5, 5, 2])