|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING |
| 4 | +if TYPE_CHECKING: |
| 5 | + import torch |
| 6 | + array = torch.Tensor |
| 7 | + from typing import Union, Sequence, Literal |
| 8 | + |
| 9 | +from torch.fft import * # noqa: F403 |
| 10 | +import torch.fft |
| 11 | + |
| 12 | +# Several torch fft functions do not map axes to dim |
| 13 | + |
| 14 | +def fftn( |
| 15 | + x: array, |
| 16 | + /, |
| 17 | + *, |
| 18 | + s: Sequence[int] = None, |
| 19 | + axes: Sequence[int] = None, |
| 20 | + norm: Literal["backward", "ortho", "forward"] = "backward", |
| 21 | + **kwargs, |
| 22 | +) -> array: |
| 23 | + return torch.fft.fftn(x, s=s, dim=axes, norm=norm, **kwargs) |
| 24 | + |
| 25 | +def ifftn( |
| 26 | + x: array, |
| 27 | + /, |
| 28 | + *, |
| 29 | + s: Sequence[int] = None, |
| 30 | + axes: Sequence[int] = None, |
| 31 | + norm: Literal["backward", "ortho", "forward"] = "backward", |
| 32 | + **kwargs, |
| 33 | +) -> array: |
| 34 | + return torch.fft.ifftn(x, s=s, dim=axes, norm=norm, **kwargs) |
| 35 | + |
| 36 | +def rfftn( |
| 37 | + x: array, |
| 38 | + /, |
| 39 | + *, |
| 40 | + s: Sequence[int] = None, |
| 41 | + axes: Sequence[int] = None, |
| 42 | + norm: Literal["backward", "ortho", "forward"] = "backward", |
| 43 | + **kwargs, |
| 44 | +) -> array: |
| 45 | + return torch.fft.rfftn(x, s=s, dim=axes, norm=norm, **kwargs) |
| 46 | + |
| 47 | +def irfftn( |
| 48 | + x: array, |
| 49 | + /, |
| 50 | + *, |
| 51 | + s: Sequence[int] = None, |
| 52 | + axes: Sequence[int] = None, |
| 53 | + norm: Literal["backward", "ortho", "forward"] = "backward", |
| 54 | + **kwargs, |
| 55 | +) -> array: |
| 56 | + return torch.fft.irfftn(x, s=s, dim=axes, norm=norm, **kwargs) |
| 57 | + |
| 58 | +def fftshift( |
| 59 | + x: array, |
| 60 | + /, |
| 61 | + *, |
| 62 | + axes: Union[int, Sequence[int]] = None, |
| 63 | + **kwargs, |
| 64 | +) -> array: |
| 65 | + return torch.fft.fftshift(x, dim=axes, **kwargs) |
| 66 | + |
| 67 | +def ifftshift( |
| 68 | + x: array, |
| 69 | + /, |
| 70 | + *, |
| 71 | + axes: Union[int, Sequence[int]] = None, |
| 72 | + **kwargs, |
| 73 | +) -> array: |
| 74 | + return torch.fft.ifftshift(x, dim=axes, **kwargs) |
| 75 | + |
| 76 | + |
| 77 | +__all__ = torch.fft.__all__ + [ |
| 78 | + "fftn", |
| 79 | + "ifftn", |
| 80 | + "rfftn", |
| 81 | + "irfftn", |
| 82 | + "fftshift", |
| 83 | + "ifftshift", |
| 84 | +] |
0 commit comments