diff --git a/python/paddle/fft.py b/python/paddle/fft.py index d73c034c0a070..f8aba1b5ade9c 100644 --- a/python/paddle/fft.py +++ b/python/paddle/fft.py @@ -12,7 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Sequence +from __future__ import annotations + +from typing import TYPE_CHECKING, Literal, Sequence import numpy as np @@ -25,6 +27,11 @@ from .tensor.attribute import is_floating_point, is_integer from .tensor.creation import _complex_to_real_dtype, _real_to_complex_dtype +if TYPE_CHECKING: + from paddle import Tensor + from paddle._typing import DTypeLike + + _NormalizeMode = Literal["forward", "backward", "ortho"] __all__ = [ 'fft', 'ifft', @@ -156,7 +163,13 @@ def _check_at_least_ndim(x, rank): # public APIs 1d -def fft(x, n=None, axis=-1, norm="backward", name=None): +def fft( + x: Tensor, + n: int | None = None, + axis: int = -1, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Calculate one-dimensional discrete Fourier transform. @@ -165,7 +178,7 @@ def fft(x, n=None, axis=-1, norm="backward", name=None): Args: x (Tensor): The input data. It's a Tensor type. It's a complex. - n (int, optional): The length of the output transform axis. If `n` is less than + n (int|None, optional): The length of the output transform axis. If `n` is less than the length input, the input will be cropped. If larger, the input is filled with zeros. If `n` is not given, the input length along the axis specified by `axis` is used. @@ -177,7 +190,7 @@ def fft(x, n=None, axis=-1, norm="backward", name=None): the forward transforms and scaling by ``1/n`` on the `ifft`. "forward" instead applies the ``1/n`` factor on the forward transform. For ``norm="ortho"``, both directions are scaled by ``1/sqrt(n)``. - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -207,7 +220,13 @@ def fft(x, n=None, axis=-1, norm="backward", name=None): return fft_c2c(x, n, axis, norm, forward=True, name=name) -def ifft(x, n=None, axis=-1, norm="backward", name=None): +def ifft( + x: Tensor, + n: int | None = None, + axis: int = -1, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the 1-D inverse discrete Fourier Transform. @@ -269,7 +288,13 @@ def ifft(x, n=None, axis=-1, norm="backward", name=None): return fft_c2c(x, n, axis, norm, forward=False, name=name) -def rfft(x, n=None, axis=-1, norm="backward", name=None): +def rfft( + x: Tensor, + n: int | None = None, + axis: int = -1, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ The one dimensional FFT for real input. @@ -283,15 +308,15 @@ def rfft(x, n=None, axis=-1, norm="backward", name=None): ``n//2 + 1``. Args: - x(Tensor) : Real-valued input tensor - n(int, optional): Number of points along transformation axis in the + x (Tensor) : Real-valued input tensor + n (int, optional): Number of points along transformation axis in the input to use. If `n` is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If `n` is not given, the length of the input along the axis specified by `axis` is used. - axis(int, optional): Axis over which to compute the FFT. Default value + axis (int, optional): Axis over which to compute the FFT. Default value is last axis. - norm(str, optional) : Normalization mode, indicates which direction of + norm (str, optional) : Normalization mode, indicates which direction of the forward/backward pair of transforms is scaled and with what normalization factor. Include {"backward", "ortho", "forward"}, default value is "backward". @@ -301,7 +326,7 @@ def rfft(x, n=None, axis=-1, norm="backward", name=None): - "ortho": The factor of forward direction and backward direction are both ``1/sqrt(n)``. Where ``n`` is the multiplication of each element in ``s`` . - name(str, optional): The default value is None. Normally there is no + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` . @@ -322,7 +347,13 @@ def rfft(x, n=None, axis=-1, norm="backward", name=None): return fft_r2c(x, n, axis, norm, forward=True, onesided=True, name=name) -def irfft(x, n=None, axis=-1, norm="backward", name=None): +def irfft( + x: Tensor, + n: int | None = None, + axis: int = -1, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Computes the inverse of `rfft`. @@ -348,7 +379,7 @@ def irfft(x, n=None, axis=-1, norm="backward", name=None): norm (str, optional): Indicates which direction to scale the `forward` or `backward` transform pair and what normalization factor to use. The parameter value must be one of "forward" or "backward" or "ortho". Default is "backward". - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` . Returns: @@ -373,7 +404,13 @@ def irfft(x, n=None, axis=-1, norm="backward", name=None): return fft_c2r(x, n, axis, norm, forward=False, name=name) -def hfft(x, n=None, axis=-1, norm="backward", name=None): +def hfft( + x: Tensor, + n: int | None = None, + axis: int = -1, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the FFT of a signal that has Hermitian symmetry, a real spectrum. @@ -416,7 +453,13 @@ def hfft(x, n=None, axis=-1, norm="backward", name=None): return fft_c2r(x, n, axis, norm, forward=True, name=name) -def ihfft(x, n=None, axis=-1, norm="backward", name=None): +def ihfft( + x: Tensor, + n: int | None = None, + axis: int = -1, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ The inverse FFT of a signal that has Hermitian symmetry. @@ -430,19 +473,19 @@ def ihfft(x, n=None, axis=-1, norm="backward", name=None): ``n//2 + 1``. Args: - x(Tensor): Input tensor. - n(int, optional): The number of points along transformation axis in the + x (Tensor): Input tensor. + n (int|None, optional): The number of points along transformation axis in the input to use. If `n` is smaller than the length of the input, the input is cropped. If it is larger, the input is padded with zeros. If `n` is not given, the length of the input along the axis specified by `axis` is used. - axis(int, optional) : Axis over which to compute the inverse FFT. If not + axis (int, optional) : Axis over which to compute the inverse FFT. If not given, the last axis is used. - norm(str, optional) : Normalization mode, indicates which direction of + norm (str, optional) : Normalization mode, indicates which direction of the forward/backward pair of transforms is scaled and with what normalization factor. Include {"backward", "ortho", "forward"}, default value is "backward". - name(str, optional): The default value is None. Normally there is no + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` . @@ -472,7 +515,13 @@ def ihfft(x, n=None, axis=-1, norm="backward", name=None): # public APIs nd -def fftn(x, s=None, axes=None, norm="backward", name=None): +def fftn( + x: Tensor, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the N-D discrete Fourier Transform. @@ -540,7 +589,13 @@ def fftn(x, s=None, axes=None, norm="backward", name=None): return fftn_c2c(x, s, axes, norm, forward=True, name=name) -def ifftn(x, s=None, axes=None, norm="backward", name=None): +def ifftn( + x: Tensor, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the N-D inverse discrete Fourier Transform. @@ -558,14 +613,14 @@ def ifftn(x, s=None, axes=None, norm="backward", name=None): Args: x (Tensor): The input data. It's a Tensor type. It's a complex. - s (sequence of ints, optional): Shape (length of each transformed axis) of the output + s (sequence of ints|None, optional): Shape (length of each transformed axis) of the output (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). This corresponds to ``n`` for ``fft(x, n)``. Along any axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if `s` is not given, the shape of the input along the axes specified by `axes` is used. - axes (sequence of ints, optional): Axes used to calculate FFT. If not given, the last ``len(s)`` + axes (sequence of ints|None, optional): Axes used to calculate FFT. If not given, the last ``len(s)`` axes are used, or all axes if `s` is also not specified. norm (str, optional): Indicates which direction to scale the `forward` or `backward` transform pair and what normalization factor to use. The parameter value must be one @@ -573,7 +628,7 @@ def ifftn(x, s=None, axes=None, norm="backward", name=None): the forward transforms and scaling by ``1/n`` on the `ifft`. "forward" instead applies the ``1/n`` factor on the forward transform. For ``norm="ortho"``, both directions are scaled by ``1/sqrt(n)``. - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -608,7 +663,13 @@ def ifftn(x, s=None, axes=None, norm="backward", name=None): return fftn_c2c(x, s, axes, norm, forward=False, name=name) -def rfftn(x, s=None, axes=None, norm="backward", name=None): +def rfftn( + x: Tensor, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ The N dimensional FFT for real input. @@ -626,15 +687,15 @@ def rfftn(x, s=None, axes=None, norm="backward", name=None): transformation axes. Args: - x(Tensor) : Input tensor, taken to be real. - s(Sequence[int], optional) : Shape to use from the exec fft. The final element of + x (Tensor) : Input tensor, taken to be real. + s (Sequence[int]|None, optional) : Shape to use from the exec fft. The final element of `s` corresponds to `n` for ``rfft(x, n)``, while for the remaining axes, it corresponds to `n` for ``fft(x, n)``. Along any axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if `s` is not given, the shape of the input along the axes specified by `axes` is used. - axes(Sequence[int], optional) : Axes over which to compute the FFT. If not given, + axes(Sequence[int]|None, optional) : Axes over which to compute the FFT. If not given, the last ``len(s)`` axes are used, or all axes if `s` is also not specified. norm(str, optional) : Normalization mode, indicates which direction of @@ -650,7 +711,7 @@ def rfftn(x, s=None, axes=None, norm="backward", name=None): - "ortho": The factor of forward direction and backward direction are both ``1/sqrt(n)``. Where ``n`` is the multiplication of each element in ``s`` . - name(str, optional): The default value is None. Normally there is no + name(str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` . @@ -687,7 +748,13 @@ def rfftn(x, s=None, axes=None, norm="backward", name=None): return fftn_r2c(x, s, axes, norm, forward=True, onesided=True, name=name) -def irfftn(x, s=None, axes=None, norm="backward", name=None): +def irfftn( + x: Tensor, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Computes the inverse of `rfftn`. @@ -704,7 +771,7 @@ def irfftn(x, s=None, axes=None, norm="backward", name=None): Args: x (Tensor): The input data. It's a Tensor type. - s (sequence of ints, optional): The length of the output transform axis. + s (sequence of ints|None, optional): The length of the output transform axis. (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). - `s` is also the number of input points used along this axis, except for the last axis, where ``s[-1]//2+1`` points of the input are used. @@ -713,7 +780,7 @@ def irfftn(x, s=None, axes=None, norm="backward", name=None): where ``k`` is the length of the input along that axis. - axes (sequence of ints, optional): Axes over which to compute the inverse FFT. If not given, the last + axes (sequence of ints|None, optional): Axes over which to compute the inverse FFT. If not given, the last `len(s)` axes are used, or all axes if `s` is also not specified. norm (str): Indicates which direction to scale the `forward` or `backward` transform pair and what normalization factor to use. The parameter value must be one @@ -725,7 +792,7 @@ def irfftn(x, s=None, axes=None, norm="backward", name=None): - "ortho": The factor of forward direction and backward direction are both ``1/sqrt(n)``. Where ``n`` is the multiplication of each element in ``s`` . - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -757,7 +824,13 @@ def irfftn(x, s=None, axes=None, norm="backward", name=None): return fftn_c2r(x, s, axes, norm, forward=False, name=name) -def hfftn(x, s=None, axes=None, norm="backward", name=None): +def hfftn( + x: Tensor, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the N-D FFT of Hermitian symmetric complex input, i.e., a signal with a real spectrum. @@ -770,7 +843,7 @@ def hfftn(x, s=None, axes=None, norm="backward", name=None): Args: x (Tensor): The input data. It's a Tensor type. - s (sequence of ints, optional): The length of the output transform axis. + s (sequence of ints|None, optional): The length of the output transform axis. (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). `s` is also the number of input points used along this axis, except for the last axis, where ``s[-1]//2+1`` points of the input are used. Along any axis, if @@ -779,12 +852,12 @@ def hfftn(x, s=None, axes=None, norm="backward", name=None): If `s` is not given, the shape of the input along the axes specified by axes is used. Except for the last axis which is taken to be ``2*(k-1)`` where ``k`` is the length of the input along that axis. - axes (sequence of ints, optional): Axes over which to compute the inverse FFT. If not given, the last + axes (sequence of ints|None, optional): Axes over which to compute the inverse FFT. If not given, the last `len(s)` axes are used, or all axes if `s` is also not specified. norm (str, optional): Indicates which direction to scale the `forward` or `backward` transform pair and what normalization factor to use. The parameter value must be one of "forward" or "backward" or "ortho". Default is "backward". - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -806,7 +879,13 @@ def hfftn(x, s=None, axes=None, norm="backward", name=None): return fftn_c2r(x, s, axes, norm, forward=True, name=name) -def ihfftn(x, s=None, axes=None, norm="backward", name=None): +def ihfftn( + x: Tensor, + s: Sequence[int] | None = None, + axes: Sequence[int] | None = None, + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ The n dimensional inverse FFT of a signal that has Hermitian symmetry. @@ -815,20 +894,20 @@ def ihfftn(x, s=None, axes=None, norm="backward", name=None): efficient algorithm called the Fast Fourier Transform (FFT). Args: - x(Tensor): Input tensor. - s(Sequence[int], optional) : Shape (length along each transformed axis) + x (Tensor): Input tensor. + s (Sequence[int]|None, optional) : Shape (length along each transformed axis) to use from the input. (``s[0]`` refers to axis 0, ``s[1]`` to axis 1, etc.). Along any axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if `s` is not given, the shape of the input along the axes specified by `axes` is used. - axes(Sequence[int], optional) : Axis over which to compute the inverse FFT. If not + axes (Sequence[int]|None, optional) : Axis over which to compute the inverse FFT. If not given, the last axis is used. norm(str, optional) : Normalization mode, indicates which direction of the forward/backward pair of transforms is scaled and with what normalization factor. Include {"backward", "ortho", "forward"}, default value is "backward". - name(str, optional): The default value is None. Normally there is no + name(str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` . @@ -857,7 +936,13 @@ def ihfftn(x, s=None, axes=None, norm="backward", name=None): # public APIs 2d -def fft2(x, s=None, axes=(-2, -1), norm="backward", name=None): +def fft2( + x: Tensor, + s: list[int] | tuple[int, int] | None = None, + axes: list[int] | tuple[int, int] = (-2, -1), + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the 2-D discrete Fourier Transform @@ -868,7 +953,7 @@ def fft2(x, s=None, axes=(-2, -1), norm="backward", name=None): Args: x (Tensor): The input data. It's a Tensor type. - s (sequence of ints, optional): Shape (length of each transformed axis) of the output. + s (sequence of ints|None, optional): Shape (length of each transformed axis) of the output. It should be a sequence of 2 integers. This corresponds to ``n`` for ``fft(x, n)``. Along each axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. @@ -879,7 +964,7 @@ def fft2(x, s=None, axes=(-2, -1), norm="backward", name=None): norm (str, optional): Indicates which direction to scale the `forward` or `backward` transform pair and what normalization factor to use. The parameter value must be one of "forward" or "backward" or "ortho". Default is "backward". - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -916,7 +1001,13 @@ def fft2(x, s=None, axes=(-2, -1), norm="backward", name=None): return fftn(x, s, axes, norm, name) -def ifft2(x, s=None, axes=(-2, -1), norm="backward", name=None): +def ifft2( + x: Tensor, + s: list[int] | tuple[int, int] | None = None, + axes: list[int] | tuple[int, int] = (-2, -1), + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the 2-D inverse discrete Fourier Transform. @@ -935,18 +1026,18 @@ def ifft2(x, s=None, axes=(-2, -1), norm="backward", name=None): Args: x (Tensor): The input data. It's a Tensor type. - s (sequence of ints, optional): Shape (length of each transformed axis) of the output. - It should be a sequence of 2 integers. This corresponds to ``n`` for ``fft(x, n)``. + s (sequence of ints|None, optional): Shape (length of each transformed axis) of the output. + It should be a sequence of 2 integers. This corresponds to ``n`` for ``ifft(x, n)``. Along each axis, if the given shape is smaller than that of the input, the input is cropped. If it is larger, the input is padded with zeros. if `s` is not given, the shape of the input along the axes specified by `axes` is used. Default is None. - axes (sequence of ints, optional): Axes over which to compute the FFT. It should be a + axes (sequence of ints, optional): Axes over which to compute the inverse FFT. It should be a sequence of 2 integers. If not specified, the last two axes are used by default. norm (str, optional): Indicates which direction to scale the `forward` or `backward` transform pair and what normalization factor to use. The parameter value must be one of "forward" or "backward" or "ortho". Default is "backward". - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -982,7 +1073,13 @@ def ifft2(x, s=None, axes=(-2, -1), norm="backward", name=None): return ifftn(x, s, axes, norm, name) -def rfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): +def rfft2( + x: Tensor, + s: list[int] | tuple[int, int] | None = None, + axes: list[int] | tuple[int, int] = (-2, -1), + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ The two dimensional FFT with real tensor input. @@ -990,10 +1087,16 @@ def rfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): For more details see `rfftn`. Args: - x(Tensor): Input tensor, taken to be real. - s(Sequence[int], optional) : Shape of the FFT. - axes(Sequence[int], optional): Axes over which to compute the FFT. - norm(str, optional) : {"backward", "ortho", "forward"}, + x (Tensor): Input tensor, taken to be real. + s (sequence[int]|None, optional): Shape (length of each transformed axis) of the output. + It should be a sequence of 2 integers. This corresponds to ``n`` for ``rfft(x, n)``. + Along each axis, if the given shape is smaller than that of the input, + the input is cropped. If it is larger, the input is padded with zeros. + if `s` is not given, the shape of the input along the axes specified + by `axes` is used. Default is None. + axes (sequence[int], optional): Axes over which to compute the FFT. It should be a + sequence of 2 integers. If not specified, the last two axes are used by default. + norm (str, optional) : {"backward", "ortho", "forward"}, default is "backward". Indicates which direction of the forward/backward pair of transforms is scaled and with what normalization factor. The details of @@ -1004,7 +1107,7 @@ def rfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): - "ortho": The factor of forward direction and backward direction are both ``1/sqrt(n)``. Where ``n`` is the multiplication of each element in ``s`` . - name(str, optional): The default value is None. Normally there is no + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` . @@ -1042,15 +1145,26 @@ def rfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): return rfftn(x, s, axes, norm, name) -def irfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): +def irfft2( + x: Tensor, + s: list[int] | tuple[int, int] | None = None, + axes: list[int] | tuple[int, int] = (-2, -1), + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Computes the inverse of `rfft2`. Args: x (Tensor): The input data. It's a Tensor type. - s (sequence of ints, optional): Shape of the real output to the inverse FFT. Default is None. - axes (sequence of ints, optional): The axes over which to compute the inverse FFT. Axes - must be two-dimensional. If not specified, the last two axes are used by default. + s (sequence[int]|None, optional): Shape (length of each transformed axis) of the output. + It should be a sequence of 2 integers. This corresponds to ``n`` for ``irfft(x, n)``. + Along each axis, if the given shape is smaller than that of the input, + the input is cropped. If it is larger, the input is padded with zeros. + if `s` is not given, the shape of the input along the axes specified + by `axes` is used. Default is None. + axes (sequence[int], optional): Axes over which to compute the inverse FFT. It should be a + sequence of 2 integers. If not specified, the last two axes are used by default. norm (str, optional): Indicates which direction to scale the `forward` or `backward` transform pair and what normalization factor to use. The parameter value must be one of "forward" or "backward" or "ortho". Default is "backward". The details of @@ -1061,7 +1175,7 @@ def irfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): - "ortho": The factor of forward direction and backward direction are both ``1/sqrt(n)``. Where ``n`` is the multiplication of each element in ``s`` . - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` . Returns: @@ -1094,19 +1208,30 @@ def irfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): return irfftn(x, s, axes, norm, name) -def hfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): +def hfft2( + x: Tensor, + s: list[int] | tuple[int, int] | None = None, + axes: list[int] | tuple[int, int] = (-2, -1), + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the 2-D FFT of a Hermitian complex array. Args: x (Tensor): The input data. It's a Tensor type. - s (sequence of ints, optional): Shape of the real output. Default is None. - axes (sequence of ints, optional): Axes over which to compute the FFT. Axes must be - two-dimensional. If not specified, the last two axes are used by default. + s (sequence[int]|None, optional): Shape (length of each transformed axis) of the output. + It should be a sequence of 2 integers. This corresponds to ``n`` for ``hfft(x, n)``. + Along each axis, if the given shape is smaller than that of the input, + the input is cropped. If it is larger, the input is padded with zeros. + if `s` is not given, the shape of the input along the axes specified + by `axes` is used. Default is None. + axes (sequence[int], optional): Axes over which to compute the FFT. It should be a + sequence of 2 integers. If not specified, the last two axes are used by default. norm (str): Indicates which direction to scale the `forward` or `backward` transform pair and what normalization factor to use. The parameter value must be one of "forward" or "backward" or "ortho". Default is "backward". - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -1139,7 +1264,13 @@ def hfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): return hfftn(x, s, axes, norm, name) -def ihfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): +def ihfft2( + x: Tensor, + s: list[int] | tuple[int, int] | None = None, + axes: list[int] | tuple[int, int] = (-2, -1), + norm: _NormalizeMode = "backward", + name: str | None = None, +) -> Tensor: """ Compute the two dimensional inverse FFT of a real spectrum. @@ -1147,13 +1278,18 @@ def ihfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): For more details see `ihfftn`. Args: - x(Tensor): Input tensor. - s(Sequence[int], optional): Shape of the real input to the inverse FFT. - axes(Sequence[int], optional): The axes over which to compute the - inverse fft. Default is the last two axes. - norm(str, optional): {"backward", "ortho", "forward"}. Default is + x (Tensor): Input tensor. + s (sequence[int]|None, optional): Shape (length of each transformed axis) of the output. + It should be a sequence of 2 integers. This corresponds to ``n`` for ``ihfft(x, n)``. + Along each axis, if the given shape is smaller than that of the input, + the input is cropped. If it is larger, the input is padded with zeros. + if `s` is not given, the shape of the input along the axes specified + by `axes` is used. Default is None. + axes (sequence[int], optional): Axes over which to compute the inverse FFT. It should be a + sequence of 2 integers. If not specified, the last two axes are used by default. + norm (str, optional): {"backward", "ortho", "forward"}. Default is "backward". - name(str, optional): The default value is None. Normally there is no + name (str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name` . @@ -1199,7 +1335,12 @@ def ihfft2(x, s=None, axes=(-2, -1), norm="backward", name=None): # public APIs utilities -def fftfreq(n, d=1.0, dtype=None, name=None): +def fftfreq( + n: int, + d: float = 1.0, + dtype: DTypeLike | None = None, + name: str | None = None, +) -> Tensor: """ Return the Discrete Fourier Transform sample frequencies. @@ -1214,7 +1355,9 @@ def fftfreq(n, d=1.0, dtype=None, name=None): Args: n (int): Dimension inputed. - d (scalar, optional): Sample spacing (inverse of the sampling rate). Defaults is 1. + d (float, optional): Sample spacing (inverse of the sampling rate). Defaults is 1. + dtype (str, optional): The data type of returns. Defaults is the data type of returns + of ``paddle.get_default_dtype()``. name (str, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. @@ -1245,7 +1388,12 @@ def fftfreq(n, d=1.0, dtype=None, name=None): return indices * val -def rfftfreq(n, d=1.0, dtype=None, name=None): +def rfftfreq( + n: int, + d: float = 1.0, + dtype: DTypeLike | None = None, + name: str | None = None, +) -> Tensor: """ Return the Discrete Fourier Transform sample frequencies. @@ -1261,7 +1409,7 @@ def rfftfreq(n, d=1.0, dtype=None, name=None): Args: n (int): Dimension inputed. - d (scalar, optional): Sample spacing (inverse of the sampling rate). Defaults is 1. + d (float, optional): Sample spacing (inverse of the sampling rate). Defaults is 1. dtype (str, optional): The data type of returns. Defaults is the data type of returns of ``paddle.get_default_dtype()``. name (str, optional): The default value is None. Normally there is no need for user to set @@ -1293,7 +1441,9 @@ def rfftfreq(n, d=1.0, dtype=None, name=None): return indices * val -def fftshift(x, axes=None, name=None): +def fftshift( + x: Tensor, axes: Sequence[int] | None = None, name: str | None = None +) -> Tensor: """ Shift the zero-frequency component to the center of the spectrum. @@ -1302,9 +1452,9 @@ def fftshift(x, axes=None, name=None): Args: n (int): Dimension inputed. - axes (int|tuple, optional): The axis on which to move. The default is none, which moves all axes. + axes (int|tuple|None, optional): The axis on which to move. The default is none, which moves all axes. Default is None. - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: @@ -1340,16 +1490,18 @@ def fftshift(x, axes=None, name=None): return paddle.roll(x, shifts, axes, name=name) -def ifftshift(x, axes=None, name=None): +def ifftshift( + x: Tensor, axes: Sequence[int] | None = None, name: str | None = None +) -> Tensor: """ The inverse of `fftshift`. Although the even length 'x' is the same, the function of the odd length 'x' is different. An example. Args: n (int): Dimension inputed. - axes (int|tuple, optional): The axis on which to move. The default is none, which moves all axes. + axes (int|tuple|None, optional): The axis on which to move. The default is none, which moves all axes. Default is None. - name (str, optional): The default value is None. Normally there is no need for user to set + name (str|None, optional): The default value is None. Normally there is no need for user to set this property. For more information, please refer to :ref:`api_guide_Name`. Returns: