KinWaiCheuk / nnAudio

Audio processing by using pytorch 1D convolution network

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

torch.rfft has been moved

THasthika opened this issue · comments

torch.rfft should be ported to torch.fft.rfft

Vc = torch.rfft(v, 1, onesided=False)

ceps = torch.rfft(spec, 1, onesided=False)[:,:,:,0]/np.sqrt(self.N)

spec = torch.rfft(ceps, 1, onesided=False)[:,:,:,0]/np.sqrt(self.N)

ceps = torch.rfft(spec, 1, onesided=False)[:,:,:,0]/np.sqrt(self.N)

Hi THasthika, thanks for pointing it out! Indeed torch.rfft is not longer available since PyTorch 1.8. But it is better to keep the support for older versions, since torch.fft.rfft is not available before version 1.7.

One solution I can think of is to import rfft functions differently based on the PyTorch version the user is using. Something similar to this stackoverflow post.

In our case it would be like

if torch.__version__<1.7:
    import torch.rfft as rfft
else:
    import torch.fft.rfft as rfft

Then in the main code, we replace torch.rfft by rfft.

Would you like to make a pull request? I am a little busy recently, so it might took me a while to check and do it myself.

@KinWaiCheuk It was not as simple as that since PyTorch has adopted the Complex data type for fft functions. I had to use the torch.fft.fft to compute the equivalent in the newer versions. I've created a simple helper function rfft_fn to determine the function to run.

Thanks for the quick pull request! The workflow you added is really helpful too.