Skip to content

Conversation

@peterbell10
Copy link
Collaborator

@peterbell10 peterbell10 commented Sep 22, 2020

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.

Stack from ghstack:

Differential Revision: D24363639

@dr-ci
Copy link

dr-ci bot commented Sep 22, 2020

💊 CI failures summary and remediations

As 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.

See how this bot performed.

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]
peterbell10 added a commit that referenced this pull request Sep 23, 2020
ghstack-source-id: 65f0767
Pull Request resolved: #45164
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]
peterbell10 added a commit that referenced this pull request Sep 23, 2020
ghstack-source-id: 923c39c
Pull Request resolved: #45164
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]
peterbell10 added a commit that referenced this pull request Oct 5, 2020
ghstack-source-id: 60b5fec
Pull Request resolved: #45164
@mruberry mruberry added module: fft and removed fft labels Oct 6, 2020
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]
peterbell10 added a commit that referenced this pull request Oct 7, 2020
ghstack-source-id: 384b212
Pull Request resolved: #45164
@skipCPUIfNoMkl
@skipCUDAIfRocm
@onlyOnCPUAndCUDA
@unittest.skipIf(not TEST_NUMPY, 'NumPy not found')
Copy link
Collaborator

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


# Once with dim defaulted
input_np = input.cpu().numpy()
expected = numpy_fn(input_np, s, axes=(-2, -1), norm=norm)
Copy link
Collaborator

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?

return torch::fft_ifft(self, n, dim, norm);
}

/// Computes the 2 dimensional fast Fourier transform over given dimensions.
Copy link
Collaborator

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"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"2 dimensional" -> "2-dimensional"

return torch::fft_fft2(self, s, dim, norm);
}

/// Computes the 2 dimensional fast Fourier transform over given dimensions.
Copy link
Collaborator

@mruberry mruberry Oct 12, 2020

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.

return torch::fft_irfft(self, n, dim, norm);
}

/// Computes the 2 dimensional FFT of real input with onesided Hermitian output.
Copy link
Collaborator

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."?

/// Example:
/// ```
/// auto t = torch::randn({128, 128}, dtype=kComplexDouble);
/// torch::fft::irfftn(t);
Copy link
Collaborator

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`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"2 dimensional" -> "2-dimensional"

Computes the 2 dimensional discrete Fourier transform of :attr:`input`.
Note:
:func:`~torch.fft.fft2` is a convenience alias for :func:`~torch.fft.fftn`
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

@mruberry
Copy link
Collaborator

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]
peterbell10 added a commit that referenced this pull request Oct 12, 2020
ghstack-source-id: e8c06f7
Pull Request resolved: #45164
""")

ifft2 = _add_docstr(_fft.fft_ifft2, r"""
ifftn(input, s=None, dim=(-2, -1), norm=None) -> Tensor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ifftn->ifft2

Copy link
Collaborator

@mruberry mruberry left a 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]
@peterbell10
Copy link
Collaborator Author

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]
peterbell10 added a commit that referenced this pull request Oct 16, 2020
ghstack-source-id: 36b28d2
Pull Request resolved: #45164
@facebook-github-bot
Copy link
Contributor

@mruberry merged this pull request in da95eec.

@facebook-github-bot facebook-github-bot deleted the gh/peterbell10/14/head branch October 21, 2020 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: fft open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants