Last active
July 20, 2021 10:29
-
-
Save speedcell4/21ab246930928d15beed079922717eaf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from torch import Tensor | |
from torch.testing import assert_close | |
def fft(tensor: Tensor, pi: Tensor = torch.acos(torch.tensor(-1.))) -> Tensor: | |
n = tensor.size()[-1] | |
index = torch.arange(n, dtype=torch.float32) | |
fourier = torch.exp(index[:, None] * index[None, :] * pi * -2j / n) | |
return tensor.to(dtype=fourier.dtype) @ fourier | |
a = torch.randn((1, 4)) | |
assert_close(fft(a), torch.fft.fft(a, dim=-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment