Skip to content

Commit

Permalink
Merge pull request #121 from jorenham/complete/scipy.fftpack
Browse files Browse the repository at this point in the history
complete `scipy.fftpack`
  • Loading branch information
jorenham authored Oct 21, 2024
2 parents 457ef12 + 567155f commit d0b9cfa
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 129 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pip install scipy-stubs
| `constants` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon_with_face: |
| `datasets` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon_with_face: |
| `fft` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_crescent_moon: |
| `fftpack` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_crescent_moon: |
| `fftpack` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| `integrate` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :waxing_gibbous_moon: |
| `interpolate` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :first_quarter_moon: |
| `io` | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :full_moon: |
Expand Down
36 changes: 35 additions & 1 deletion scipy-stubs/fftpack/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,39 @@
from . import basic as basic, helper as helper, pseudo_diffs as pseudo_diffs, realtransforms as realtransforms
from . import basic as basic, helper as helper, pseudo_diffs as pseudo_diffs, realtransforms as realtransforms # deprecated
from ._basic import *
from ._helper import *
from ._pseudo_diffs import *
from ._realtransforms import *

__all__ = [
"cc_diff",
"cs_diff",
"dct",
"dctn",
"diff",
"dst",
"dstn",
"fft",
"fft2",
"fftfreq",
"fftn",
"fftshift",
"hilbert",
"idct",
"idctn",
"idst",
"idstn",
"ifft",
"ifft2",
"ifftn",
"ifftshift",
"ihilbert",
"irfft",
"itilbert",
"next_fast_len",
"rfft",
"rfftfreq",
"sc_diff",
"shift",
"ss_diff",
"tilbert",
]
78 changes: 68 additions & 10 deletions scipy-stubs/fftpack/_basic.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,68 @@
from scipy._typing import Untyped

def fft(x: Untyped, n: Untyped | None = None, axis: int = -1, overwrite_x: bool = False) -> Untyped: ...
def ifft(x: Untyped, n: Untyped | None = None, axis: int = -1, overwrite_x: bool = False) -> Untyped: ...
def rfft(x: Untyped, n: Untyped | None = None, axis: int = -1, overwrite_x: bool = False) -> Untyped: ...
def irfft(x: Untyped, n: Untyped | None = None, axis: int = -1, overwrite_x: bool = False) -> Untyped: ...
def fftn(x: Untyped, shape: Untyped | None = None, axes: Untyped | None = None, overwrite_x: bool = False) -> Untyped: ...
def ifftn(x: Untyped, shape: Untyped | None = None, axes: Untyped | None = None, overwrite_x: bool = False) -> Untyped: ...
def fft2(x: Untyped, shape: Untyped | None = None, axes: Untyped = (-2, -1), overwrite_x: bool = False) -> Untyped: ...
def ifft2(x: Untyped, shape: Untyped | None = None, axes: Untyped = (-2, -1), overwrite_x: bool = False) -> Untyped: ...
from typing import Protocol, TypeAlias, type_check_only

import numpy as np
import numpy.typing as npt
from numpy._typing import _ArrayLikeFloat_co, _ArrayLikeNumber_co
from optype import CanIndex
from scipy._typing import AnyBool, AnyShape

__all__ = ["fft", "fft2", "fftn", "ifft", "ifft2", "ifftn", "irfft", "rfft"]

_ArrayReal: TypeAlias = npt.NDArray[np.float32 | np.float64 | np.longdouble] # no float16
_ArrayComplex: TypeAlias = npt.NDArray[np.complex64 | np.complex128 | np.clongdouble]

@type_check_only
class _OrderedIndex(CanIndex, Protocol):
def __lt__(self, other: CanIndex, /) -> bool: ...
def __le__(self, other: CanIndex, /) -> bool: ...

###

def fft(
x: _ArrayLikeNumber_co,
n: _OrderedIndex | None = None,
axis: CanIndex = -1,
overwrite_x: AnyBool = False,
) -> _ArrayComplex: ...
def ifft(
x: _ArrayLikeNumber_co,
n: _OrderedIndex | None = None,
axis: CanIndex = -1,
overwrite_x: AnyBool = False,
) -> _ArrayComplex: ...
def rfft(
x: _ArrayLikeFloat_co,
n: _OrderedIndex | None = None,
axis: CanIndex = -1,
overwrite_x: AnyBool = False,
) -> _ArrayReal: ...
def irfft(
x: _ArrayLikeFloat_co,
n: _OrderedIndex | None = None,
axis: CanIndex = -1,
overwrite_x: AnyBool = False,
) -> _ArrayReal: ...
def fftn(
x: _ArrayLikeNumber_co,
shape: AnyShape | None = None,
axes: AnyShape | None = None,
overwrite_x: AnyBool = False,
) -> _ArrayComplex: ...
def ifftn(
x: _ArrayLikeNumber_co,
shape: AnyShape | None = None,
axes: AnyShape | None = None,
overwrite_x: AnyBool = False,
) -> _ArrayComplex: ...
def fft2(
x: _ArrayLikeNumber_co,
shape: AnyShape | None = None,
axes: tuple[CanIndex, CanIndex] = (-2, -1),
overwrite_x: AnyBool = False,
) -> _ArrayComplex: ...
def ifft2(
x: _ArrayLikeNumber_co,
shape: AnyShape | None = None,
axes: tuple[CanIndex, CanIndex] = (-2, -1),
overwrite_x: AnyBool = False,
) -> _ArrayComplex: ...
8 changes: 5 additions & 3 deletions scipy-stubs/fftpack/_helper.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import numpy as np
import optype.numpy as onpt
from numpy.fft import fftfreq, fftshift, ifftshift # noqa: ICN003
from scipy._typing import Untyped
from scipy._typing import AnyInt, AnyReal

__all__ = ["fftfreq", "fftshift", "ifftshift", "next_fast_len", "rfftfreq"]

def rfftfreq(n: Untyped, d: float = 1.0) -> Untyped: ...
def next_fast_len(target: Untyped) -> Untyped: ...
def rfftfreq(n: AnyInt, d: AnyReal = 1.0) -> onpt.Array[tuple[int], np.float64]: ...
def next_fast_len(target: AnyInt) -> int: ...
84 changes: 73 additions & 11 deletions scipy-stubs/fftpack/_pseudo_diffs.pyi
Original file line number Diff line number Diff line change
@@ -1,14 +1,76 @@
from scipy._typing import Untyped
from typing import TypeAlias, overload

import numpy as np
import optype.numpy as onpt
from numpy._typing import _ArrayLikeFloat_co, _ArrayLikeNumber_co
from scipy._typing import AnyReal

__all__ = ["cc_diff", "cs_diff", "diff", "hilbert", "ihilbert", "itilbert", "sc_diff", "shift", "ss_diff", "tilbert"]

def diff(x: Untyped, order: int = 1, period: Untyped | None = None, _cache: Untyped = ...) -> Untyped: ...
def tilbert(x: Untyped, h: Untyped, period: Untyped | None = None, _cache: Untyped = ...) -> Untyped: ...
def itilbert(x: Untyped, h: Untyped, period: Untyped | None = None, _cache: Untyped = ...) -> Untyped: ...
def hilbert(x: Untyped, _cache: Untyped = ...) -> Untyped: ...
def ihilbert(x: Untyped) -> Untyped: ...
def cs_diff(x: Untyped, a: Untyped, b: Untyped, period: Untyped | None = None, _cache: Untyped = ...) -> Untyped: ...
def sc_diff(x: Untyped, a: Untyped, b: Untyped, period: Untyped | None = None, _cache: Untyped = ...) -> Untyped: ...
def ss_diff(x: Untyped, a: Untyped, b: Untyped, period: Untyped | None = None, _cache: Untyped = ...) -> Untyped: ...
def cc_diff(x: Untyped, a: Untyped, b: Untyped, period: Untyped | None = None, _cache: Untyped = ...) -> Untyped: ...
def shift(x: Untyped, a: Untyped, period: Untyped | None = None, _cache: Untyped = ...) -> Untyped: ...
# the suffix correspond to the relevant dtype charcode(s)
_Vec_d: TypeAlias = onpt.Array[tuple[int], np.float64]
_Vec_dD: TypeAlias = onpt.Array[tuple[int], np.float64 | np.complex128]

_Cache: TypeAlias = dict[tuple[AnyReal, ...], _Vec_d] # {n: kernel}

###

#
@overload
def diff(x: _ArrayLikeFloat_co, order: int = 1, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def diff(x: _ArrayLikeNumber_co, order: int = 1, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_dD: ...

#
@overload
def tilbert(x: _ArrayLikeFloat_co, h: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def tilbert(x: _ArrayLikeNumber_co, h: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_dD: ...

#
@overload
def itilbert(x: _ArrayLikeFloat_co, h: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def itilbert(x: _ArrayLikeNumber_co, h: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_dD: ...

#
@overload
def hilbert(x: _ArrayLikeFloat_co, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def hilbert(x: _ArrayLikeNumber_co, _cache: _Cache = ...) -> _Vec_dD: ...

#
@overload
def ihilbert(x: _ArrayLikeFloat_co) -> _Vec_d: ...
@overload
def ihilbert(x: _ArrayLikeNumber_co) -> _Vec_dD: ...

#
@overload
def cs_diff(x: _ArrayLikeFloat_co, a: AnyReal, b: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def cs_diff(x: _ArrayLikeNumber_co, a: AnyReal, b: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_dD: ...

#
@overload
def sc_diff(x: _ArrayLikeFloat_co, a: AnyReal, b: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def sc_diff(x: _ArrayLikeNumber_co, a: AnyReal, b: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_dD: ...

#
@overload
def ss_diff(x: _ArrayLikeFloat_co, a: AnyReal, b: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def ss_diff(x: _ArrayLikeNumber_co, a: AnyReal, b: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_dD: ...

#
@overload
def cc_diff(x: _ArrayLikeFloat_co, a: AnyReal, b: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def cc_diff(x: _ArrayLikeNumber_co, a: AnyReal, b: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_dD: ...

#
@overload
def shift(x: _ArrayLikeFloat_co, a: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_d: ...
@overload
def shift(x: _ArrayLikeNumber_co, a: AnyReal, period: AnyReal | None = None, _cache: _Cache = ...) -> _Vec_dD: ...
Loading

0 comments on commit d0b9cfa

Please sign in to comment.