pytorch_fft
pytorch_fft copied to clipboard
why is there a '/2' for backword of rfft?
I am new to pytorch, and I am trying create rfft (real-to-complex fast fourier transoformation) operator using Caffe2 with Eigen. When I came into this code `class Rfft(torch.autograd.Function): def forward(self, X_re): X_re = X_re.contiguous() self._to_save_input_size = X_re.size(-1) return rfft(X_re)
def backward(self, grad_output_re, grad_output_im):
# Clone the array and make contiguous if needed
grad_output_re = contiguous_clone(grad_output_re)
grad_output_im = contiguous_clone(grad_output_im)
if self._to_save_input_size & 1:
grad_output_re[...,1:] /= 2
else:
grad_output_re[...,1:-1] /= 2
if self._to_save_input_size & 1:
grad_output_im[...,1:] /= 2
else:
grad_output_im[...,1:-1] /= 2
gr = irfft(grad_output_re,grad_output_im,self._to_save_input_size, normalize=False)
return gr`
I am not quite clear why there is ' /= 2' ? Is it for the lack of image part of rfft input? Thanks in advance for help!