Skip to content

Commit 92cfd8e

Browse files
authored
fft: improved [i]fftshift annotations (#682)
2 parents 6744bfc + b4766ef commit 92cfd8e

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

scipy-stubs/fft/_helper.pyi

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,51 @@
1+
from _typeshed import Incomplete
12
from types import ModuleType
2-
from typing import Any, Literal, TypeVar, overload
3+
from typing import Literal, TypeVar, overload
34

45
import numpy as np
56
import optype as op
67
import optype.numpy as onp
7-
from numpy._typing import _ArrayLike
8+
import optype.numpy.compat as npc
89

910
from scipy._typing import AnyShape
1011

11-
_SCT = TypeVar("_SCT", bound=np.inexact[Any])
12+
_InexactT = TypeVar("_InexactT", bound=npc.inexact)
1213

1314
def next_fast_len(target: op.CanIndex, real: op.CanBool = False) -> int: ...
1415
def prev_fast_len(target: op.CanIndex, real: op.CanBool = False) -> int: ...
1516

1617
#
1718
@overload # xp: None -> np.fft.fftfreq
1819
def fftfreq(
19-
n: int | np.integer[Any], d: onp.ToFloat = 1.0, *, xp: None = None, device: Literal["cpu"] | None = None
20+
n: int | npc.integer, d: onp.ToFloat = 1.0, *, xp: None = None, device: Literal["cpu"] | None = None
2021
) -> onp.Array1D[np.float64]: ...
2122
@overload # xp: ModuleType -> xp.fft.fftfreq
22-
def fftfreq(n: int, d: float = 1.0, *, xp: ModuleType, device: object | None = None) -> Any: ...
23+
def fftfreq(n: int, d: float = 1.0, *, xp: ModuleType, device: object | None = None) -> Incomplete: ...
2324

2425
#
2526
@overload # np.fft.rfftfreq
2627
def rfftfreq(
27-
n: int | np.integer[Any], d: onp.ToFloat = 1.0, *, xp: None = None, device: Literal["cpu"] | None = None
28+
n: int | npc.integer, d: onp.ToFloat = 1.0, *, xp: None = None, device: Literal["cpu"] | None = None
2829
) -> onp.Array1D[np.float64]: ...
29-
@overload # xp.fft.fftfreq
30-
def rfftfreq(n: int, d: float = 1.0, *, xp: ModuleType, device: object | None = None) -> Any: ...
30+
@overload
31+
def rfftfreq(n: int, d: float = 1.0, *, xp: ModuleType, device: object | None = None) -> Incomplete: ...
3132

3233
#
3334
@overload
34-
def fftshift(x: onp.ToIntND | onp.SequenceND[float], axes: AnyShape | None = None) -> onp.ArrayND[np.float64]: ...
35+
def fftshift(x: onp.ToIntND | onp.ToJustFloat64_ND, axes: AnyShape | None = None) -> onp.ArrayND[np.float64]: ...
3536
@overload
36-
def fftshift(x: onp.SequenceND[complex], axes: AnyShape | None = None) -> onp.ArrayND[np.complex128 | np.float64]: ...
37+
def fftshift(x: onp.ToJustComplex128_ND, axes: AnyShape | None = None) -> onp.ArrayND[np.complex128]: ...
3738
@overload
38-
def fftshift(x: _ArrayLike[_SCT], axes: AnyShape | None = None) -> onp.ArrayND[_SCT]: ...
39+
def fftshift(x: onp.ToArrayND[_InexactT, _InexactT], axes: AnyShape | None = None) -> onp.ArrayND[_InexactT]: ...
3940
@overload
40-
def fftshift(x: onp.ToComplexND, axes: AnyShape | None = None) -> onp.ArrayND[np.inexact[Any]]: ...
41+
def fftshift(x: onp.ToComplexND, axes: AnyShape | None = None) -> onp.ArrayND[npc.inexact]: ...
4142

4243
#
4344
@overload
44-
def ifftshift(x: onp.ToIntND | onp.SequenceND[float], axes: AnyShape | None = None) -> onp.ArrayND[np.float64]: ...
45+
def ifftshift(x: onp.ToIntND | onp.ToJustFloat64_ND, axes: AnyShape | None = None) -> onp.ArrayND[np.float64]: ...
4546
@overload
46-
def ifftshift(x: onp.SequenceND[complex], axes: AnyShape | None = None) -> onp.ArrayND[np.complex128 | np.float64]: ...
47+
def ifftshift(x: onp.ToJustComplex128_ND, axes: AnyShape | None = None) -> onp.ArrayND[np.complex128]: ...
4748
@overload
48-
def ifftshift(x: _ArrayLike[_SCT], axes: AnyShape | None = None) -> onp.ArrayND[_SCT]: ...
49+
def ifftshift(x: onp.ToArrayND[_InexactT, _InexactT], axes: AnyShape | None = None) -> onp.ArrayND[_InexactT]: ...
4950
@overload
50-
def ifftshift(x: onp.ToComplexND, axes: AnyShape | None = None) -> onp.ArrayND[np.inexact[Any]]: ...
51+
def ifftshift(x: onp.ToComplexND, axes: AnyShape | None = None) -> onp.ArrayND[npc.inexact]: ...

0 commit comments

Comments
 (0)