Skip to content

Commit fa991d8

Browse files
committed
🩹 fix compatibility issues with np.[c]longdouble on numpy<2.2
1 parent a52f9a7 commit fa991d8

32 files changed

+136
-161
lines changed

‎scipy-stubs/fft/_basic.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ _CoInteger: TypeAlias = npc.integer | np.bool_
1717

1818
_AsFloat32: TypeAlias = onp.CanArrayND[npc.floating32, _ShapeT]
1919
_AsFloat64: TypeAlias = onp.CanArrayND[npc.floating64 | _CoInteger, _ShapeT]
20-
_AsFloat80: TypeAlias = onp.CanArrayND[np.longdouble, _ShapeT]
20+
_AsFloat80: TypeAlias = onp.CanArrayND[npc.floating80, _ShapeT]
2121

2222
_AsComplex64: TypeAlias = onp.CanArrayND[npc.inexact32, _ShapeT]
2323
_AsComplex128: TypeAlias = onp.CanArrayND[npc.inexact64 | _CoInteger, _ShapeT]
24-
_AsComplex160: TypeAlias = onp.CanArrayND[np.longdouble | np.clongdouble, _ShapeT]
24+
_AsComplex160: TypeAlias = onp.CanArrayND[npc.inexact80, _ShapeT]
2525

2626
_ToFloat64_ND: TypeAlias = onp.ToArrayND[float, npc.floating64 | _CoInteger]
2727
_ToComplex128_ND: TypeAlias = onp.ToArrayND[complex, npc.inexact64 | _CoInteger]

‎scipy-stubs/fft/_fftlog.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import optype.numpy.compat as npc
77

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

10-
_FloatT = TypeVar("_FloatT", bound=np.float32 | np.float64 | np.longdouble)
10+
_FloatT = TypeVar("_FloatT", bound=np.float32 | np.float64 | npc.floating80)
1111
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
1212

1313
###

‎scipy-stubs/fft/_realtransforms.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ from scipy._typing import AnyShape
1010

1111
__all__ = ["dct", "dctn", "dst", "dstn", "idct", "idctn", "idst", "idstn"]
1212

13-
_DTypeT = TypeVar("_DTypeT", bound=np.dtype[np.float32 | np.float64 | np.longdouble | npc.complexfloating])
13+
_DTypeT = TypeVar("_DTypeT", bound=np.dtype[np.float32 | np.float64 | npc.floating80 | npc.complexfloating])
1414
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
1515

1616
_ToIntOrND: TypeAlias = onp.ToInt | onp.ToIntND
17-
_FloatND: TypeAlias = onp.ArrayND[np.float32 | np.float64 | np.longdouble] # doesn't include `numpy.float16`
17+
_FloatND: TypeAlias = onp.ArrayND[np.float32 | np.float64 | np.longdouble]
1818

1919
###
2020
# NOTE: These have (almost) identical signatures, so be sure to keep them in sync.

‎scipy-stubs/fft/_realtransforms_backend.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ from scipy._typing import AnyShape
1212
__all__ = ["dct", "dctn", "dst", "dstn", "idct", "idctn", "idst", "idstn"]
1313

1414
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
15-
_DTypeT = TypeVar("_DTypeT", bound=np.dtype[np.float32 | np.float64 | np.longdouble | npc.complexfloating])
15+
_DTypeT = TypeVar("_DTypeT", bound=np.dtype[np.float32 | np.float64 | npc.floating80 | npc.complexfloating])
1616

1717
# NOTE: Unlike the ones in `scipy.fft._realtransforms`, `orthogonalize` is keyword-only here.
1818

‎scipy-stubs/fftpack/_basic.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ from typing import Protocol, TypeAlias, type_check_only
33
import numpy as np
44
import optype as op
55
import optype.numpy as onp
6+
import optype.numpy.compat as npc
67

78
from scipy._typing import AnyShape
89

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

1112
_ArrayReal: TypeAlias = onp.ArrayND[np.float32 | np.float64 | np.longdouble] # no float16
12-
_ArrayComplex: TypeAlias = onp.ArrayND[np.complex64 | np.complex128 | np.clongdouble]
13+
_ArrayComplex: TypeAlias = onp.ArrayND[npc.complexfloating]
1314

1415
@type_check_only
1516
class _OrderedIndex(op.CanIndex, Protocol):

‎scipy-stubs/fftpack/_realtransforms.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from typing import Literal, TypeAlias, overload
33
import numpy as np
44
import optype as op
55
import optype.numpy as onp
6+
import optype.numpy.compat as npc
67

78
from scipy._typing import AnyShape
89
from scipy.fft._typing import DCTType
@@ -12,7 +13,7 @@ __all__ = ["dct", "dctn", "dst", "dstn", "idct", "idctn", "idst", "idstn"]
1213
_NormKind: TypeAlias = Literal["ortho"] | None
1314

1415
_ArrayReal: TypeAlias = onp.ArrayND[np.float32 | np.float64 | np.longdouble] # no float16
15-
_ArrayComplex: TypeAlias = onp.ArrayND[np.complex64 | np.complex128 | np.clongdouble]
16+
_ArrayComplex: TypeAlias = onp.ArrayND[npc.complexfloating]
1617

1718
###
1819

‎scipy-stubs/integrate/_ivp/common.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ class OdeSolution(Generic[_InterpT_co]):
4444
@overload
4545
def __call__(self, /, t: op.JustComplex | np.complex128 | np.complex64) -> onp.Array1D[np.complex128]: ...
4646
@overload
47-
def __call__(self, /, t: np.longdouble) -> onp.Array1D[np.longdouble]: ...
47+
def __call__(self, /, t: npc.floating80) -> onp.Array1D[np.longdouble]: ...
4848
@overload
49-
def __call__(self, /, t: np.clongdouble) -> onp.Array1D[np.clongdouble]: ...
49+
def __call__(self, /, t: npc.complexfloating160) -> onp.Array1D[np.clongdouble]: ...
5050
@overload
5151
def __call__(self, /, t: onp.ToArray1D[float, _ToFloat64]) -> onp.Array2D[np.float64]: ...
5252
@overload
5353
def __call__(self, /, t: onp.ToArray1D[op.JustComplex, np.complex128 | np.complex64]) -> onp.Array2D[np.complex128]: ...
5454
@overload
55-
def __call__(self, /, t: onp.CanArrayND[np.clongdouble]) -> onp.Array2D[np.clongdouble]: ...
55+
def __call__(self, /, t: onp.CanArrayND[npc.complexfloating160]) -> onp.Array2D[np.clongdouble]: ...
5656

5757
def validate_first_step(first_step: _ToFloatT, t0: onp.ToFloat, t_bound: onp.ToFloat) -> _ToFloatT: ... # undocumented
5858
def validate_max_step(max_step: _ToFloatT) -> _ToFloatT: ... # undocumented

‎scipy-stubs/io/matlab/_mio_utils.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def squeeze_element(arr: onp.Array0D[npc.integer]) -> int: ...
2626
@overload
2727
def squeeze_element(arr: onp.Array0D[np.float16 | np.float32 | np.float64]) -> float: ... # type: ignore[overload-overlap]
2828
@overload
29-
def squeeze_element(arr: onp.Array0D[np.longdouble]) -> np.longdouble: ...
29+
def squeeze_element(arr: onp.Array0D[npc.floating80]) -> np.longdouble: ...
3030
@overload
3131
def squeeze_element(arr: onp.Array0D[np.complex64 | np.complex128]) -> complex: ... # type: ignore[overload-overlap]
3232
@overload
33-
def squeeze_element(arr: onp.Array0D[np.clongdouble]) -> np.clongdouble: ...
33+
def squeeze_element(arr: onp.Array0D[npc.complexfloating160]) -> np.clongdouble: ...
3434
@overload
3535
def squeeze_element(arr: onp.Array0D[np.bytes_]) -> bytes: ...
3636
@overload

‎scipy-stubs/linalg/_basic.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ _Inexact0D: TypeAlias = onp.Array0D[_Inexact]
4040
_Inexact1D: TypeAlias = onp.Array1D[_Inexact]
4141
_InexactND: TypeAlias = onp.ArrayND[_Inexact]
4242

43-
_InputFloat: TypeAlias = onp.ToArrayND[float, np.float64 | np.longdouble | npc.integer | np.bool_]
44-
_InputFloatStrict1D: TypeAlias = onp.ToArrayStrict1D[float, np.float64 | np.longdouble | npc.integer | np.bool_]
45-
_InputFloatStrict2D: TypeAlias = onp.ToArrayStrict2D[float, np.float64 | np.longdouble | npc.integer | np.bool_]
43+
_InputFloat: TypeAlias = onp.ToArrayND[float, np.float64 | npc.floating80 | npc.integer | np.bool_]
44+
_InputFloatStrict1D: TypeAlias = onp.ToArrayStrict1D[float, np.float64 | npc.floating80 | npc.integer | np.bool_]
45+
_InputFloatStrict2D: TypeAlias = onp.ToArrayStrict2D[float, np.float64 | npc.floating80 | npc.integer | np.bool_]
4646

4747
_InputF64: TypeAlias = onp.ToArrayND[float, np.float64 | npc.integer | np.bool_]
4848
_InputF64Strict1D: TypeAlias = onp.ToArrayStrict1D[float, np.float64 | npc.integer | np.bool_]
4949
_InputF64Strict2D: TypeAlias = onp.ToArrayStrict2D[float, np.float64 | npc.integer | np.bool_]
5050

51-
_InputComplex: TypeAlias = onp.ToArrayND[op.JustComplex, np.complex128 | np.clongdouble]
52-
_InputComplexStrict1D: TypeAlias = onp.ToArrayStrict1D[op.JustComplex, np.complex128 | np.clongdouble]
53-
_InputComplexStrict2D: TypeAlias = onp.ToArrayStrict2D[op.JustComplex, np.complex128 | np.clongdouble]
51+
_InputComplex: TypeAlias = onp.ToArrayND[op.JustComplex, np.complex128 | npc.complexfloating160]
52+
_InputComplexStrict1D: TypeAlias = onp.ToArrayStrict1D[op.JustComplex, np.complex128 | npc.complexfloating160]
53+
_InputComplexStrict2D: TypeAlias = onp.ToArrayStrict2D[op.JustComplex, np.complex128 | npc.complexfloating160]
5454

5555
_AssumeA: TypeAlias = Literal[
5656
"diagonal",
@@ -1022,7 +1022,7 @@ def inv(
10221022
) -> onp.ArrayND[np.float32, _ShapeT]: ...
10231023
@overload # generic shape, as float64
10241024
def inv(
1025-
a: onp.CanArrayND[np.float64 | np.longdouble | npc.integer64 | npc.integer32, _ShapeT],
1025+
a: onp.CanArrayND[np.float64 | npc.floating80 | npc.integer64 | npc.integer32, _ShapeT],
10261026
overwrite_a: bool = False,
10271027
check_finite: bool = True,
10281028
) -> onp.ArrayND[np.float64, _ShapeT]: ...
@@ -1032,7 +1032,7 @@ def inv(
10321032
) -> onp.ArrayND[np.complex64, _ShapeT]: ...
10331033
@overload # generic shape, as complex128
10341034
def inv(
1035-
a: onp.CanArrayND[np.complex128 | np.clongdouble, _ShapeT], overwrite_a: bool = False, check_finite: bool = True
1035+
a: onp.CanArrayND[np.complex128 | npc.complexfloating160, _ShapeT], overwrite_a: bool = False, check_finite: bool = True
10361036
) -> onp.ArrayND[np.complex128, _ShapeT]: ...
10371037

10381038
# NOTE: The order of the overloads has been carefully chosen to avoid triggering a Pyright bug.

‎scipy-stubs/linalg/_cythonized_array_utils.pyi

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,12 @@ from typing import TypeAlias
22

33
import numpy as np
44
import optype.numpy as onp
5+
import optype.numpy.compat as npc
56

67
__all__ = ["bandwidth", "ishermitian", "issymmetric"]
78

89
# see `scipy/linalg/_cythonized_array_utils.pxd`
9-
_Numeric: TypeAlias = (
10-
np.int8
11-
| np.int16
12-
| np.int32
13-
| np.int64
14-
| np.uint8
15-
| np.uint16
16-
| np.uint32
17-
| np.uint64
18-
| np.float32
19-
| np.float64
20-
| np.longdouble
21-
| np.complex64
22-
| np.complex128
23-
)
10+
_Numeric: TypeAlias = npc.integer | np.float32 | np.float64 | npc.floating80 | np.complex64 | np.complex128
2411

2512
def bandwidth(a: onp.ArrayND[_Numeric]) -> tuple[int, int]: ...
2613
def issymmetric(a: onp.ArrayND[_Numeric], atol: float | None = None, rtol: float | None = None) -> bool: ...

0 commit comments

Comments
 (0)