Hi:)
I want to calculate the inverse FFT of a truncated input vector,
Python 3.8.10 (default, May 19 2021, 18:05:58)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x = torch.rand(5)
>>> fx = torch.fft.fft(x)
>>> fx
tensor([3.2079+0.0000j, 0.3252+0.3854j, 0.1552+0.6282j, 0.1552-0.6282j, 0.3252-0.3854j])
>>> fx[2] = 0.
>>> fx[3] = 0.
>>> fx
tensor([3.2079+0.0000j, 0.3252+0.3854j, 0.0000+0.0000j, 0.0000+0.0000j, 0.3252-0.3854j])
>>> torch.fft.ifft(fx)
tensor([0.7717+0.j, 0.5352+0.j, 0.4457+0.j, 0.6269+0.j, 0.8284+0.j])

Note that the truncation affects the highest frequency modes and since both, fx[2] and fx[3], are set to zero the result of ifft is real-valued as expected.
Naively, I would expect that torch.fft.ifft gives the very same result when the frequency components are truncated rather than set to zero,
>>> torch.fft.ifft(torch.tensor([fx[0], fx[1], fx[4]]), n=5)
tensor([0.7717+0.0000j, 0.5811+0.1863j, 0.4905-0.1098j, 0.7277-0.0625j, 0.6370-0.0139j])

but the result is now different and complex.
Obviously, I am missing something, probably, I misunderstand the parameter n?
Any ideas?