-
Notifications
You must be signed in to change notification settings - Fork 26.3k
torch.fft: Two dimensional FFT functions #45164
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
Conversation
[ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit bc3bd1b (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group. This comment has been revised 47 times. |
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
test/test_spectral_ops.py
Outdated
| @skipCPUIfNoMkl | ||
| @skipCUDAIfRocm | ||
| @onlyOnCPUAndCUDA | ||
| @unittest.skipIf(not TEST_NUMPY, 'NumPy not found') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now require NumPy in our test suite and don't need these checks anymore
test/test_spectral_ops.py
Outdated
|
|
||
| # Once with dim defaulted | ||
| input_np = input.cpu().numpy() | ||
| expected = numpy_fn(input_np, s, axes=(-2, -1), norm=norm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting. Should this not explicitly provide a value for axes to be consistent with the actual computation below?
torch/csrc/api/include/torch/fft.h
Outdated
| return torch::fft_ifft(self, n, dim, norm); | ||
| } | ||
|
|
||
| /// Computes the 2 dimensional fast Fourier transform over given dimensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"over given" -> "over the given"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"2 dimensional" -> "2-dimensional"
torch/csrc/api/include/torch/fft.h
Outdated
| return torch::fft_fft2(self, s, dim, norm); | ||
| } | ||
|
|
||
| /// Computes the 2 dimensional fast Fourier transform over given dimensions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Computes the inverse of torch.fft.fft2.
torch/csrc/api/include/torch/fft.h
Outdated
| return torch::fft_irfft(self, n, dim, norm); | ||
| } | ||
|
|
||
| /// Computes the 2 dimensional FFT of real input with onesided Hermitian output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be: "of a real input. Returns a onesided Hermitian output."?
torch/csrc/api/include/torch/fft.h
Outdated
| /// Example: | ||
| /// ``` | ||
| /// auto t = torch::randn({128, 128}, dtype=kComplexDouble); | ||
| /// torch::fft::irfftn(t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a call to irfft2, not irfftn
| fft2 = _add_docstr(_fft.fft_fft2, r""" | ||
| fft2(input, s=None, dim=(-2, -1), norm=None) -> Tensor | ||
| Computes the 2 dimensional discrete Fourier transform of :attr:`input`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"2 dimensional" -> "2-dimensional"
torch/fft/__init__.py
Outdated
| Computes the 2 dimensional discrete Fourier transform of :attr:`input`. | ||
| Note: | ||
| :func:`~torch.fft.fft2` is a convenience alias for :func:`~torch.fft.fftn` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of making this a note, how about adding a second sentence to the preamble like: "Equivalent to ..." and linking fftn and showing how to map the arguments from this to fftn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mruberry PTAL, I've changed it but am not entirely sure about "map[ping] the arguments from this to fftn". The arguments should be exactly the same, other than dim not accepting None.
|
Hey @peterbell10! Great to have these last few functions. As usual I've asked a few questions about the docs. Sorry about the review delay but review responsiveness should finally be back to normal. Looking forward to hearing your thoughts! |
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
torch/fft/__init__.py
Outdated
| """) | ||
|
|
||
| ifft2 = _add_docstr(_fft.fft_ifft2, r""" | ||
| ifftn(input, s=None, dim=(-2, -1), norm=None) -> Tensor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ifftn->ifft2
mruberry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another awesome PR, @peterbell10! Just one minor correction in the docs. Ping me when you're ready.
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
|
Fixed. Thanks @mruberry. |
This PR implements `fft2`, `ifft2`, `rfft2` and `irfft2`. These are the last functions required for `torch.fft` to match `numpy.fft`. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to `*fftn` in every way, except for the default value of `axes`. In fact you can even use `fft2` to do general n-dimensional transforms. [ghstack-poisoned]
This PR implements
fft2,ifft2,rfft2andirfft2. These are the last functions required fortorch.fftto matchnumpy.fft. If you look at either NumPy or SciPy you'll see that the 2-dimensional variants are identical to*fftnin every way, except for the default value ofaxes. In fact you can even usefft2to do general n-dimensional transforms.Stack from ghstack:
Differential Revision: D24363639