Hi Avitase!



 avitase:

I actually do need the complex version


Okay, I think I understand your use case now.  Indeed, for the complex
case, rfft() won’t work, and, as you noted, naive padding also doesn’t
work.
I suppose you could use fftshift(), zero out the ends of the vector,
and restore the required order with ifftshift() before applying ifft().
But that would be a little verbose for my taste.  I would just do the
necessary index arithmetic to zero out the high-frequency components:
>>> fx
tensor([ 6.9995+0.0000j, -0.5333+0.5133j, -0.4665+0.1265j, -0.4665-0.1265j,
        -0.5333-0.5133j])
>>> nZero = 2
>>> fxc = fx.clone()
>>> l = len (fxc)
>>> fxc[(l - nZero + 1) // 2 : (l + nZero + 1) // 2] = 0.0
>>> fxc
tensor([ 6.9995+0.0000j, -0.5333+0.5133j,  0.0000+0.0000j,  0.0000+0.0000j,
        -0.5333-0.5133j])
>>> torch.fft.ifft (fxc)
tensor([1.1866+0.j, 1.1387+0.j, 1.4518+0.j, 1.6932+0.j, 1.5293+0.j])

Best.
K. Frank