Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module 'torch' has no attribute 'rfft' #26

Open
aoliao12138 opened this issue Jun 5, 2022 · 5 comments
Open

module 'torch' has no attribute 'rfft' #26

aoliao12138 opened this issue Jun 5, 2022 · 5 comments

Comments

@aoliao12138
Copy link

When I try to run the example, I get a runtime error

>>> X = dct.dct(x)   # DCT-II done through the last dimension
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/torch_dct/_dct.py", line 48, in dct
    Vc = torch.rfft(v, 1, onesided=False)
AttributeError: module 'torch' has no attribute 'rfft'

my torch version is '1.10.2+cu113'. Did I miss something?

Also, I want to ask what is scaled DCT? Does the input of scaled DCT need to be in range [0,1]?

Thank you very much!

@yrj1409
Copy link

yrj1409 commented Jun 8, 2022

'torch.rfft' is removed after torch1.9

@CollinWeightman
Copy link

if you can read Chinese, here is the solution:
https://aitechtogether.com/article/37264.html

@MaloShady
Copy link

Found the solution hidden in another post: #15 (comment)

To migrate the DCT code to the newest pytorch version, you only have to change two lines; one in dct, one in idct.

dct:

#Vc = torch.rfft(v, 1, onesided=False)           # comment this line
Vc = torch.view_as_real(torch.fft.fft(v, dim=1))  # add this line

idct:

# v = torch.irfft(V, 1, onesided=False)                             # comment this line
v= torch.fft.irfft(torch.view_as_complex(V), n=V.shape[1], dim=1)   # add this line

Took me wayyy too long to figure out. Hope it helps you!

@RobinHistory
Copy link

RobinHistory commented Nov 2, 2022

Thanks for the solution @MaloShady .
But I have a question.
In dct1():
return torch.rfft(torch.cat([x, x.flip([1])[:, 1:-1]], dim=1), 1)[:, :, 0].view(*x_shape).
I think new torch use fft to replace rfft, so we need change torch.rfft to torch.fft.rfft.
If we don't use the dct1() and its inverse, there will be no bug report for this one.

@jonnor
Copy link

jonnor commented Nov 7, 2022

This can be closed now. Fixed in PR #24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants