Skip to content
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

*: switch to the shape-typed optype.numpy array-likes #192

Merged
merged 16 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
28c91df
[constants] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
be8a9b6
[fft] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
b66bfd9
[fftpack] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
f844b91
[integrate] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
ca5f31d
[interpolate] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
c47b0cd
[odr] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
cc54f0b
[optimize] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
949d5a3
[signal] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
25be180
[sparse.csgraph] prefer `optype.numpy` over `numpy._typing` for array…
jorenham Nov 23, 2024
5948ac3
[spatial] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
0a64302
[sparse.csgraph] fix stubtest error
jorenham Nov 23, 2024
af7aea1
[special] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
1fb6e8a
[stats] prefer `optype.numpy` over `numpy._typing` for array-likes
jorenham Nov 23, 2024
65faeb2
`optype.numpy.ToComplex[ND]` over `numpy._typing._ArrayLikeComplex_co`
jorenham Nov 23, 2024
20251a9
`optype.numpy.ToInt[ND]` over `numpy._typing._ArrayLikeInt[_co]`
jorenham Nov 23, 2024
d7b6d62
prefer `optype.numpy.ToComplex[ND]` over `numpy._typing._ArrayLikeNum…
jorenham Nov 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions scipy-stubs/_lib/_util.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import numpy as np
import numpy.typing as npt
import optype as op
import optype.numpy as onp
from numpy._typing import _ArrayLikeInt
from numpy.random import Generator as Generator
from scipy._typing import RNG, EnterSelfMixin

_AnyRNG = TypeVar("_AnyRNG", np.random.RandomState, np.random.Generator)
Expand Down Expand Up @@ -93,17 +91,17 @@ def check_random_state(seed: int | np.integer[Any] | types.ModuleType | None) ->
@overload
def rng_integers(
gen: RNG | None,
low: _ArrayLikeInt,
high: _ArrayLikeInt | None = None,
low: onp.ToInt | onp.ToIntND,
high: onp.ToInt | onp.ToIntND | None = None,
size: tuple[()] | None = None,
dtype: onp.AnyIntegerDType = "int64",
endpoint: op.CanBool = False,
) -> np.integer[Any]: ...
@overload
def rng_integers(
gen: RNG | None,
low: _ArrayLikeInt,
high: _ArrayLikeInt | None = None,
low: onp.ToInt | onp.ToIntND,
high: onp.ToInt | onp.ToIntND | None = None,
size: op.CanIndex | Sequence[op.CanIndex] | None = None,
dtype: onp.AnyIntegerDType = "int64",
endpoint: op.CanBool = False,
Expand Down
43 changes: 33 additions & 10 deletions scipy-stubs/constants/_constants.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import Final, Literal, TypeAlias
from typing import Any, Final, Literal, TypeAlias, TypeVar, overload

import numpy as np
import numpy.typing as npt
from numpy._typing import _ArrayLikeFloat_co
import optype.numpy as onp

__all__ = [
"N_A",
Expand Down Expand Up @@ -165,6 +164,9 @@ __all__ = [
"zetta",
]

_FloatScalarT = TypeVar("_FloatScalarT", bound=np.floating[Any])
_FloatArrayT = TypeVar("_FloatArrayT", bound=onp.ArrayND[np.floating[Any]])

_TempScaleC: TypeAlias = Literal["Celsius", "celsius", "C", "c"]
_TempScaleK: TypeAlias = Literal["Kelvin", "kelvin", "K", "k"]
_TempScaleF: TypeAlias = Literal["Fahrenheit", "fahrenheit", "F", "f"]
Expand Down Expand Up @@ -360,10 +362,31 @@ pound_force: Final = 4.4482216152605
kgf: Final = 9.80665
kilogram_force: Final = 9.80665

def convert_temperature(
val: _ArrayLikeFloat_co,
old_scale: _TempScale,
new_scale: _TempScale,
) -> np.float64 | npt.NDArray[np.float64]: ...
def lambda2nu(lambda_: _ArrayLikeFloat_co) -> np.float64 | npt.NDArray[np.float64]: ...
def nu2lambda(nu: _ArrayLikeFloat_co) -> np.float64 | npt.NDArray[np.float64]: ...
@overload
def convert_temperature(val: _FloatScalarT, old_scale: _TempScale, new_scale: _TempScale) -> _FloatScalarT: ...
@overload
def convert_temperature(val: _FloatArrayT, old_scale: _TempScale, new_scale: _TempScale) -> _FloatArrayT: ...
@overload
def convert_temperature(val: onp.ToFloat, old_scale: _TempScale, new_scale: _TempScale) -> np.floating[Any]: ...
@overload
def convert_temperature(val: onp.ToFloatND, old_scale: _TempScale, new_scale: _TempScale) -> onp.ArrayND[np.floating[Any]]: ...

#
@overload
def lambda2nu(lambda_: _FloatScalarT) -> _FloatScalarT: ...
@overload
def lambda2nu(lambda_: _FloatArrayT) -> _FloatArrayT: ...
@overload
def lambda2nu(lambda_: onp.ToFloat) -> np.floating[Any]: ...
@overload
def lambda2nu(lambda_: onp.ToFloatND) -> onp.ArrayND[np.floating[Any]]: ...

#
@overload
def nu2lambda(nu: _FloatScalarT) -> _FloatScalarT: ...
@overload
def nu2lambda(nu: _FloatArrayT) -> _FloatArrayT: ...
@overload
def nu2lambda(nu: onp.ToFloat) -> np.floating[Any]: ...
@overload
def nu2lambda(nu: onp.ToFloatND) -> onp.ArrayND[np.floating[Any]]: ...
61 changes: 30 additions & 31 deletions scipy-stubs/fft/_basic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import numpy as np
import numpy.typing as npt
import optype as op
import optype.numpy as onp
from numpy._typing import _ArrayLikeFloat_co, _ArrayLikeInt, _ArrayLikeNumber_co
from scipy._typing import AnyShape

_Norm: TypeAlias = Literal["backward", "ortho", "forward"]
Expand All @@ -16,7 +15,7 @@ _ArrayComplex: TypeAlias = npt.NDArray[np.complex64 | np.complex128 | np.clongdo
###

def fft(
x: _ArrayLikeNumber_co,
x: onp.ToComplexND,
n: onp.ToInt | None = None,
axis: op.CanIndex = -1,
norm: _Norm | None = None,
Expand All @@ -26,8 +25,8 @@ def fft(
plan: _Plan | None = None,
) -> _ArrayComplex: ...
def fft2(
x: _ArrayLikeNumber_co,
s: _ArrayLikeInt | None = None,
x: onp.ToComplexND,
s: onp.ToIntND | None = None,
axes: AnyShape = (-2, -1),
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -36,8 +35,8 @@ def fft2(
plan: _Plan | None = None,
) -> _ArrayComplex: ...
def fftn(
x: _ArrayLikeNumber_co,
s: _ArrayLikeInt | None = None,
x: onp.ToComplexND,
s: onp.ToIntND | None = None,
axes: AnyShape | None = None,
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -48,7 +47,7 @@ def fftn(

#
def ifft(
x: _ArrayLikeNumber_co,
x: onp.ToComplexND,
n: onp.ToInt | None = None,
axis: op.CanIndex = -1,
norm: _Norm | None = None,
Expand All @@ -58,8 +57,8 @@ def ifft(
plan: _Plan | None = None,
) -> _ArrayComplex: ...
def ifft2(
x: _ArrayLikeNumber_co,
s: _ArrayLikeInt | None = None,
x: onp.ToComplexND,
s: onp.ToIntND | None = None,
axes: AnyShape = (-2, -1),
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -68,8 +67,8 @@ def ifft2(
plan: _Plan | None = None,
) -> _ArrayComplex: ...
def ifftn(
x: _ArrayLikeNumber_co,
s: _ArrayLikeInt | None = None,
x: onp.ToComplexND,
s: onp.ToIntND | None = None,
axes: AnyShape | None = None,
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -80,7 +79,7 @@ def ifftn(

#
def rfft(
x: _ArrayLikeFloat_co,
x: onp.ToFloatND,
n: onp.ToInt | None = None,
axis: op.CanIndex = -1,
norm: _Norm | None = None,
Expand All @@ -90,8 +89,8 @@ def rfft(
plan: _Plan | None = None,
) -> _ArrayComplex: ...
def rfft2(
x: _ArrayLikeFloat_co,
s: _ArrayLikeInt | None = None,
x: onp.ToFloatND,
s: onp.ToIntND | None = None,
axes: AnyShape = (-2, -1),
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -100,8 +99,8 @@ def rfft2(
plan: _Plan | None = None,
) -> _ArrayComplex: ...
def rfftn(
x: _ArrayLikeFloat_co,
s: _ArrayLikeInt | None = None,
x: onp.ToFloatND,
s: onp.ToIntND | None = None,
axes: AnyShape | None = None,
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -112,7 +111,7 @@ def rfftn(

#
def irfft(
x: _ArrayLikeNumber_co,
x: onp.ToComplexND,
n: onp.ToInt | None = None,
axis: op.CanIndex = -1,
norm: _Norm | None = None,
Expand All @@ -122,8 +121,8 @@ def irfft(
plan: _Plan | None = None,
) -> _ArrayReal: ...
def irfft2(
x: _ArrayLikeNumber_co,
s: _ArrayLikeInt | None = None,
x: onp.ToComplexND,
s: onp.ToIntND | None = None,
axes: AnyShape = (-2, -1),
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -132,8 +131,8 @@ def irfft2(
plan: _Plan | None = None,
) -> _ArrayReal: ...
def irfftn(
x: _ArrayLikeNumber_co,
s: _ArrayLikeInt | None = None,
x: onp.ToComplexND,
s: onp.ToIntND | None = None,
axes: AnyShape | None = None,
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -144,7 +143,7 @@ def irfftn(

#
def hfft(
x: _ArrayLikeNumber_co,
x: onp.ToComplexND,
n: onp.ToInt | None = None,
axis: op.CanIndex = -1,
norm: _Norm | None = None,
Expand All @@ -154,8 +153,8 @@ def hfft(
plan: _Plan | None = None,
) -> _ArrayReal: ...
def hfft2(
x: _ArrayLikeNumber_co,
s: _ArrayLikeInt | None = None,
x: onp.ToComplexND,
s: onp.ToIntND | None = None,
axes: AnyShape = (-2, -1),
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -164,8 +163,8 @@ def hfft2(
plan: _Plan | None = None,
) -> _ArrayReal: ...
def hfftn(
x: _ArrayLikeNumber_co,
s: _ArrayLikeInt | None = None,
x: onp.ToComplexND,
s: onp.ToIntND | None = None,
axes: AnyShape | None = None,
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -176,7 +175,7 @@ def hfftn(

#
def ihfft(
x: _ArrayLikeFloat_co,
x: onp.ToFloatND,
n: onp.ToInt | None = None,
axis: op.CanIndex = -1,
norm: _Norm | None = None,
Expand All @@ -186,8 +185,8 @@ def ihfft(
plan: _Plan | None = None,
) -> _ArrayComplex: ...
def ihfft2(
x: _ArrayLikeFloat_co,
s: _ArrayLikeInt | None = None,
x: onp.ToFloatND,
s: onp.ToIntND | None = None,
axes: AnyShape = (-2, -1),
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand All @@ -196,8 +195,8 @@ def ihfft2(
plan: _Plan | None = None,
) -> _ArrayComplex: ...
def ihfftn(
x: _ArrayLikeFloat_co,
s: _ArrayLikeInt | None = None,
x: onp.ToFloatND,
s: onp.ToIntND | None = None,
axes: AnyShape | None = None,
norm: _Norm | None = None,
overwrite_x: op.CanBool = False,
Expand Down
12 changes: 5 additions & 7 deletions scipy-stubs/fft/_fftlog.pyi
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
from typing import TypeAlias

import numpy as np
import numpy.typing as npt
import optype.numpy as onp
from numpy._typing import _ArrayLikeFloat_co

__all__ = ["fht", "fhtoffset", "ifht"]

_ArrayReal: TypeAlias = npt.NDArray[np.float32 | np.float64 | np.longdouble]
_RealND: TypeAlias = onp.ArrayND[np.float32 | np.float64 | np.longdouble]

def fht(
a: _ArrayLikeFloat_co,
a: onp.ToFloatND,
dln: onp.ToFloat,
mu: onp.ToFloat,
offset: onp.ToFloat = 0.0,
bias: onp.ToFloat = 0.0,
) -> _ArrayReal: ...
) -> _RealND: ...
def ifht(
A: _ArrayLikeFloat_co,
A: onp.ToFloatND,
dln: onp.ToFloat,
mu: onp.ToFloat,
offset: onp.ToFloat = 0.0,
bias: onp.ToFloat = 0.0,
) -> _ArrayReal: ...
) -> _RealND: ...
def fhtoffset(dln: onp.ToFloat, mu: onp.ToFloat, initial: onp.ToFloat = 0.0, bias: onp.ToFloat = 0.0) -> np.float64: ...
19 changes: 9 additions & 10 deletions scipy-stubs/fft/_helper.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ from types import ModuleType
from typing import Any, Literal, TypeVar, overload

import numpy as np
import numpy.typing as npt
import optype as op
import optype.numpy as onp
from numpy._typing import _ArrayLike, _ArrayLikeInt_co, _ArrayLikeNumber_co, _NestedSequence
from numpy._typing import _ArrayLike, _NestedSequence
from scipy._typing import AnyShape

_SCT = TypeVar("_SCT", bound=np.inexact[Any])
Expand Down Expand Up @@ -42,21 +41,21 @@ def rfftfreq(n: int, d: float = 1.0, *, xp: ModuleType, device: object | None =
# TODO(jorenham): Array API support (for `x`)
# https://github.com/jorenham/scipy-stubs/issues/140
@overload
def fftshift(x: _ArrayLike[_SCT], axes: AnyShape | None = None) -> npt.NDArray[_SCT]: ...
def fftshift(x: _ArrayLike[_SCT], axes: AnyShape | None = None) -> onp.ArrayND[_SCT]: ...
@overload
def fftshift(x: _ArrayLikeInt_co | _NestedSequence[float], axes: AnyShape | None = None) -> npt.NDArray[np.float64]: ...
def fftshift(x: onp.ToIntND | _NestedSequence[float], axes: AnyShape | None = None) -> onp.ArrayND[np.float64]: ...
@overload
def fftshift(x: _NestedSequence[complex], axes: AnyShape | None = None) -> npt.NDArray[np.complex128 | np.float64]: ...
def fftshift(x: _NestedSequence[complex], axes: AnyShape | None = None) -> onp.ArrayND[np.complex128 | np.float64]: ...
@overload
def fftshift(x: _ArrayLikeNumber_co, axes: AnyShape | None = None) -> npt.NDArray[np.inexact[Any]]: ...
def fftshift(x: onp.ToComplexND, axes: AnyShape | None = None) -> onp.ArrayND[np.inexact[Any]]: ...

# TODO(jorenham): Array API support (for `x`)
# https://github.com/jorenham/scipy-stubs/issues/140
@overload
def ifftshift(x: _ArrayLike[_SCT], axes: AnyShape | None = None) -> npt.NDArray[_SCT]: ...
def ifftshift(x: _ArrayLike[_SCT], axes: AnyShape | None = None) -> onp.ArrayND[_SCT]: ...
@overload
def ifftshift(x: _ArrayLikeInt_co | _NestedSequence[float], axes: AnyShape | None = None) -> npt.NDArray[np.float64]: ...
def ifftshift(x: onp.ToIntND | _NestedSequence[float], axes: AnyShape | None = None) -> onp.ArrayND[np.float64]: ...
@overload
def ifftshift(x: _NestedSequence[complex], axes: AnyShape | None = None) -> npt.NDArray[np.complex128 | np.float64]: ...
def ifftshift(x: _NestedSequence[complex], axes: AnyShape | None = None) -> onp.ArrayND[np.complex128 | np.float64]: ...
@overload
def ifftshift(x: _ArrayLikeNumber_co, axes: AnyShape | None = None) -> npt.NDArray[np.inexact[Any]]: ...
def ifftshift(x: onp.ToComplexND, axes: AnyShape | None = None) -> onp.ArrayND[np.inexact[Any]]: ...
Loading