-
Notifications
You must be signed in to change notification settings - Fork 4
add wrappers for np.fft #123
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4bfcef3
TST: fft tests pass collection and xfail
ev-br c9e5fc9
ENH: implement fft
ev-br 9e0de0f
API: fft: make fft output dtype configurable
ev-br e71ce13
TST: vendor numpy's fft/test_helper.py
ev-br 8037d56
FFT: finish up the dir(np.fft) contents
ev-br File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,128 @@ | ||
def fft(): | ||
raise NotImplementedError | ||
from __future__ import annotations | ||
|
||
import functools | ||
|
||
def ifft(): | ||
raise NotImplementedError | ||
import torch | ||
|
||
from . import _dtypes_impl, _util | ||
from ._normalizations import ArrayLike, normalizer | ||
|
||
def fftn(): | ||
raise NotImplementedError | ||
|
||
def upcast(func): | ||
"""NumPy fft casts inputs to 64 bit and *returns 64-bit results*.""" | ||
|
||
def ifftn(): | ||
raise NotImplementedError | ||
@functools.wraps(func) | ||
def wrapped(tensor, *args, **kwds): | ||
target_dtype = ( | ||
_dtypes_impl.default_dtypes.complex_dtype | ||
if tensor.is_complex() | ||
else _dtypes_impl.default_dtypes.float_dtype | ||
) | ||
tensor = _util.cast_if_needed(tensor, target_dtype) | ||
return func(tensor, *args, **kwds) | ||
|
||
return wrapped | ||
|
||
def rfftn(): | ||
raise NotImplementedError | ||
|
||
@normalizer | ||
@upcast | ||
def fft(a: ArrayLike, n=None, axis=-1, norm=None): | ||
return torch.fft.fft(a, n, dim=axis, norm=norm) | ||
|
||
def irfftn(): | ||
raise NotImplementedError | ||
|
||
@normalizer | ||
@upcast | ||
def ifft(a: ArrayLike, n=None, axis=-1, norm=None): | ||
return torch.fft.ifft(a, n, dim=axis, norm=norm) | ||
|
||
def fft2(): | ||
raise NotImplementedError | ||
|
||
@normalizer | ||
@upcast | ||
def rfft(a: ArrayLike, n=None, axis=-1, norm=None): | ||
return torch.fft.rfft(a, n, dim=axis, norm=norm) | ||
|
||
def ifft2(): | ||
raise NotImplementedError | ||
|
||
@normalizer | ||
@upcast | ||
def irfft(a: ArrayLike, n=None, axis=-1, norm=None): | ||
return torch.fft.irfft(a, n, dim=axis, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def fftn(a: ArrayLike, s=None, axes=None, norm=None): | ||
return torch.fft.fftn(a, s, dim=axes, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def ifftn(a: ArrayLike, s=None, axes=None, norm=None): | ||
return torch.fft.ifftn(a, s, dim=axes, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def rfftn(a: ArrayLike, s=None, axes=None, norm=None): | ||
return torch.fft.rfftn(a, s, dim=axes, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def irfftn(a: ArrayLike, s=None, axes=None, norm=None): | ||
return torch.fft.irfftn(a, s, dim=axes, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def fft2(a: ArrayLike, s=None, axes=(-2, -1), norm=None): | ||
return torch.fft.fft2(a, s, dim=axes, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def ifft2(a: ArrayLike, s=None, axes=(-2, -1), norm=None): | ||
return torch.fft.ifft2(a, s, dim=axes, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def rfft2(a: ArrayLike, s=None, axes=(-2, -1), norm=None): | ||
return torch.fft.rfft2(a, s, dim=axes, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def irfft2(a: ArrayLike, s=None, axes=(-2, -1), norm=None): | ||
return torch.fft.irfft2(a, s, dim=axes, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def hfft(a: ArrayLike, n=None, axis=-1, norm=None): | ||
return torch.fft.hfft(a, n, dim=axis, norm=norm) | ||
|
||
|
||
@normalizer | ||
@upcast | ||
def ihfft(a: ArrayLike, n=None, axis=-1, norm=None): | ||
return torch.fft.ihfft(a, n, dim=axis, norm=norm) | ||
|
||
|
||
@normalizer | ||
def fftfreq(n, d=1.0): | ||
return torch.fft.fftfreq(n, d) | ||
|
||
|
||
@normalizer | ||
def rfftfreq(n, d=1.0): | ||
return torch.fft.rfftfreq(n, d) | ||
|
||
|
||
@normalizer | ||
def fftshift(x: ArrayLike, axes=None): | ||
return torch.fft.fftshift(x, axes) | ||
|
||
|
||
@normalizer | ||
def ifftshift(x: ArrayLike, axes=None): | ||
return torch.fft.ifftshift(x, axes) |
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Had to bump the tolerance. Not much we can do I guess, this falls straight through to pytorch.