torch.fft.rfftn#
- torch.fft.rfftn(input,s=None,dim=None,norm=None,*,out=None)→Tensor#
Computes the N-dimensional discrete Fourier transform of real
input.The FFT of a real signal is Hermitian-symmetric,
X[i_1,...,i_n]=conj(X[-i_1,...,-i_n])so the fullfftn()output contains redundant information.rfftn()instead omits the negative frequencies in thelast dimension.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: all dimensions, or the last
len(s)dimensions ifsis given.norm (str,optional) –
Normalization mode. For the forward transform(
rfftn()), 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 (irfftn()) with the samenormalization mode will apply an overall normalization of1/nbetweenthe two transforms. This is required to makeirfftn()the exact inverse.Default is
"backward"(no normalization).
- Keyword Arguments:
out (Tensor,optional) – the output tensor.
Example
>>>t=torch.rand(10,10)>>>rfftn=torch.fft.rfftn(t)>>>rfftn.size()torch.Size([10, 6])
Compared against the full output from
fftn(), we have allelements up to the Nyquist frequency.>>>fftn=torch.fft.fftn(t)>>>torch.testing.assert_close(fftn[...,:6],rfftn,check_stride=False)
The discrete Fourier transform is separable, so
rfftn()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(rfftn,two_ffts,check_stride=False)