Discrete Cosine Transform Using `torch.rfft`

torch.rfft lacks of doc and it’s hard to understand how to use it.
Actually, I’d like to use this function to implement a fast discrete cosine transform (DCT).
Please let me know if you have DCT implementations (any differentiable in PyTorch) or concrete example for torch.rfft (especially, 2D case).

1 Like

I guess you should look into the following link -
This link explains how to incorporate scipy functions into the computational graph.

Thank you for the comment. I saw the page but it is not what I really want because it converts torch tensors to numpy arrays, or vice versa.

Here is something which you can look forward to, as you have asked this provides example also. However when I went over the examples I found few typos but that you can easily see. I am suggesting this because it will give you atleast a direction to move forward if not solve your problem completely.

I also visited the repository and I found it had some issues. For example, the transforms would be slower when applying nn.DataParallel even if one had more than 1 GPU. Moreover, it seems that this repo hasn’t been updated since PyTorch 0.4.0.

I saw that too. and yes there were issues posted regarding nn.DataParallel but I thought you can make modifications to these to fit your need.

Hi everyone, I just wrote a library doing exactly this, you might want to check it out:

Would love to hear your feedback!


assert (torch.abs(x - y)).sum() < 1e-10 # x == y within numerical tolerance
numerical tolerance error cannot satisfy 1e-10, far beyond this, about 1e-3

1 Like