torch.fft.rfft2#
- torch.fft.rfft2(input,s=None,dim=(-2,-1),norm=None,*,out=None)→Tensor#
Computes the 2-dimensional discrete Fourier transform of real
input.Equivalent torfftn()but FFTs only the last two dimensions by default.The FFT of a real signal is Hermitian-symmetric,
X[i,j]=conj(X[-i,-j]),so the fullfft2()output contains redundant information.rfft2()instead omits the negative frequencies in the lastdimension.Note
Supports torch.half on CUDA with GPU Architecture SM53 or greater.However it only supports powers of 2 signal length in every transformed dimensions.
- Parameters:
input (Tensor) – the input tensor
s (Tuple[int],optional) – Signal size in the transformed dimensions.If given, each dimension
dim[i]will either be zero-padded ortrimmed to the lengths[i]before computing the real FFT.If a length-1is specified, no padding is done in that dimension.Default:s=[input.size(d)fordindim]dim (Tuple[int],optional) – Dimensions to be transformed.Default: last two dimensions.
norm (str,optional) –
Normalization mode. For the forward transform(
rfft2()), these correspond to:"forward"- normalize by1/n"backward"- no normalization"ortho"- normalize by1/sqrt(n)(making the real FFT orthonormal)
Where
n=prod(s)is the logical FFT size.Calling the backward transform (irfft2()) with the samenormalization mode will apply an overall normalization of1/nbetweenthe two transforms. This is required to makeirfft2()the exact inverse.Default is
"backward"(no normalization).
- Keyword Arguments:
out (Tensor,optional) – the output tensor.
Example
>>>t=torch.rand(10,10)>>>rfft2=torch.fft.rfft2(t)>>>rfft2.size()torch.Size([10, 6])
Compared against the full output from
fft2(), we have allelements up to the Nyquist frequency.>>>fft2=torch.fft.fft2(t)>>>torch.testing.assert_close(fft2[...,:6],rfft2,check_stride=False)
The discrete Fourier transform is separable, so
rfft2()here is equivalent to a combination offft()andrfft():>>>two_ffts=torch.fft.fft(torch.fft.rfft(t,dim=1),dim=0)>>>torch.testing.assert_close(rfft2,two_ffts,check_stride=False)