Skip to content

Commit ffcfd8f

Browse files
committed
🏷️ linalg: stub more of the internal scipy machinery
1 parent babe194 commit ffcfd8f

File tree

6 files changed

+116
-2
lines changed

6 files changed

+116
-2
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import Final, TypeVar
2+
3+
import numpy as np
4+
import optype.numpy as onp
5+
6+
_InexactT = TypeVar("_InexactT", bound=np.float32 | np.float64 | np.complex64 | np.complex128)
7+
8+
###
9+
10+
__pythran__: Final[tuple[str, str]] = ...
11+
12+
def _funm_loops(
13+
F: onp.Array2D[_InexactT], T: onp.Array2D[_InexactT], n: int, minden: _InexactT
14+
) -> tuple[onp.Array2D[_InexactT], _InexactT]: ...

scipy-stubs/linalg/_matfuncs.pyi

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from collections.abc import Callable
2-
from typing import Any, Literal, TypeAlias, TypeVar, overload
2+
from typing import Any, Final, Literal, TypeAlias, TypeVar, overload
33
from typing_extensions import deprecated
44

55
import numpy as np
@@ -28,6 +28,9 @@ __all__ = [
2828
]
2929

3030
_InexactT = TypeVar("_InexactT", bound=npc.inexact)
31+
_ComplexT = TypeVar("_ComplexT", bound=npc.complexfloating)
32+
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
33+
3134
_FuncND: TypeAlias = Callable[[onp.Array[Any, _InexactT]], onp.ToComplexND] # return type is unsafely cast to the input type
3235

3336
_ToPosInt: TypeAlias = npc.unsignedinteger | Literal[0, 1, 2, 4, 5, 6, 7, 8]
@@ -41,6 +44,23 @@ _InexactND: TypeAlias = onp.ArrayND[npc.inexact]
4144

4245
###
4346

47+
eps: Final[np.float64] = ... # undocumented
48+
feps: Final[np.float32] = ... # undocumented
49+
_array_precision: Final[dict[Literal["i", "l", "f", "d", "F", "D"], Literal[0, 1]]] = ... # undocumented
50+
51+
def _asarray_square(A: onp.ToArray2D[_InexactT]) -> onp.Array2D[_InexactT]: ... # undocumented
52+
53+
#
54+
@overload
55+
def _maybe_real(
56+
A: onp.ArrayND[npc.inexact], B: onp.ArrayND[npc.inexact64, _ShapeT], tol: float | None = None
57+
) -> onp.ArrayND[np.float64, _ShapeT]: ... # undocumented
58+
@overload
59+
def _maybe_real(
60+
A: onp.ArrayND[npc.inexact], B: onp.ArrayND[npc.inexact32, _ShapeT], tol: float | None = None
61+
) -> onp.ArrayND[np.float32, _ShapeT]: ... # undocumented
62+
63+
#
4464
@overload # +integer, +unsignedinteger
4565
def fractional_matrix_power(A: onp.ToIntND, t: _ToPosInt) -> _IntND: ...
4666
@overload # ~float64, +integer
@@ -118,6 +138,9 @@ def expm(A: onp.ToJustComplexND) -> _ComplexND: ...
118138
@overload # +complexfloating
119139
def expm(A: onp.ToComplexND) -> _InexactND: ...
120140

141+
#
142+
def _exp_sinch(x: onp.ArrayND[_ComplexT, _ShapeT]) -> onp.ArrayND[_ComplexT, _ShapeT]: ... # undocumented
143+
121144
#
122145
@overload # +integer | ~float64
123146
def cosm(A: onp.ToIntND | onp.ToJustFloat64_ND) -> _Float64ND: ...
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import Literal, TypeVar
2+
3+
import numpy as np
4+
import optype.numpy as onp
5+
6+
_InexactT = TypeVar("_InexactT", bound=np.float32 | np.float64 | np.complex64 | np.complex128)
7+
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
8+
9+
###
10+
11+
class error(Exception): ...
12+
13+
def recursive_schur_sqrtm(
14+
A: onp.ArrayND[_InexactT, _ShapeT],
15+
) -> tuple[onp.ArrayND[_InexactT, _ShapeT], Literal[0, 1], Literal[0, 1], int]: ...

scipy-stubs/linalg/_misc.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,6 @@ def norm(
173173
keepdims: AnyBool = False,
174174
check_finite: AnyBool = True,
175175
) -> np.floating[Any] | onp.ArrayND[np.floating[Any]]: ...
176+
177+
#
178+
def _datacopied(arr: onp.ArrayND, original: onp.CanArrayND) -> bool: ... # undocumented

scipy-stubs/linalg/_solvers.pyi

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from typing import Final, Literal, TypeAlias, overload
1+
from _typeshed import Incomplete
2+
from typing import Final, Literal, TypeAlias, TypeVar, overload
23

34
import numpy as np
45
import optype as op
@@ -13,6 +14,8 @@ __all__ = [
1314
"solve_sylvester",
1415
]
1516

17+
_InexactT = TypeVar("_InexactT", bound=np.float32 | np.float64 | np.complex64 | np.complex128)
18+
1619
_FloatND: TypeAlias = onp.ArrayND[np.float32 | np.float64]
1720
_ComplexND: TypeAlias = onp.ArrayND[np.complex64 | np.complex128]
1821

@@ -40,6 +43,10 @@ def solve_continuous_lyapunov(a: onp.ToComplexND, q: onp.ToJustComplexND) -> _Co
4043
#
4144
solve_lyapunov: Final = solve_continuous_lyapunov
4245

46+
#
47+
def _solve_discrete_lyapunov_direct(a: onp.Array2D[_InexactT], q: onp.Array2D[_InexactT]) -> onp.Array2D[_InexactT]: ...
48+
def _solve_discrete_lyapunov_bilinear(a: onp.Array2D[_InexactT], q: onp.Array2D[_InexactT]) -> onp.Array2D[_InexactT]: ...
49+
4350
#
4451
@overload # real
4552
def solve_discrete_lyapunov(a: onp.ToFloatND, q: onp.ToFloatND, method: _DiscreteMethod | None = None) -> _FloatND: ...
@@ -213,3 +220,25 @@ def solve_discrete_are(
213220
s: onp.ToJustComplexND,
214221
balanced: op.CanBool = True,
215222
) -> _ComplexND: ...
223+
224+
#
225+
def _are_validate_args(
226+
a: onp.ToComplexND,
227+
b: onp.ToComplexND,
228+
q: onp.ToComplexND,
229+
r: onp.ToComplexND,
230+
e: onp.ToComplexND | None,
231+
s: onp.ToComplexND | None,
232+
eq_type: Literal["care", "dare"] = "care",
233+
) -> tuple[
234+
onp.ArrayND[Incomplete], # a
235+
onp.ArrayND[Incomplete], # b
236+
onp.ArrayND[Incomplete], # q
237+
onp.ArrayND[Incomplete], # r
238+
onp.ArrayND[Incomplete], # e
239+
onp.ArrayND[Incomplete], # s
240+
int, # m
241+
int, # n
242+
type[float | complex], # r_or_c
243+
bool, # gen_or_not
244+
]: ...

scipy-stubs/linalg/_testutils.pyi

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from collections.abc import Callable, Iterable
2+
from typing import Any, Final, Generic, TypeAlias, TypeVar
3+
4+
import numpy as np
5+
import optype.numpy as onp
6+
7+
_T = TypeVar("_T")
8+
_ScalarT = TypeVar("_ScalarT", bound=np.generic)
9+
_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
10+
11+
_Ignored: TypeAlias = object
12+
13+
class _FakeMatrix(Generic[_ScalarT, _ShapeT]): # undocumented
14+
_data: onp.ArrayND[_ScalarT, _ShapeT]
15+
16+
def __init__(self, /, data: onp.ArrayND[_ScalarT, _ShapeT]) -> None: ...
17+
__array_interface__: Final[Callable[[], dict[str, Any]]] = ...
18+
19+
class _FakeMatrix2(Generic[_ScalarT, _ShapeT]): # undocumented
20+
_data: onp.ArrayND[_ScalarT, _ShapeT]
21+
def __init__(self, /, data: onp.ArrayND[_ScalarT, _ShapeT]) -> None: ...
22+
def __array__(self, /, dtype: np.dtype | None = None, copy: bool | None = None) -> onp.ArrayND[_ScalarT, _ShapeT]: ...
23+
24+
def _get_array(shape: _ShapeT, dtype: type[_ScalarT]) -> onp.ArrayND[_ScalarT, _ShapeT]: ... # undocumented
25+
def _id(x: _T) -> _T: ... # undocumented
26+
27+
#
28+
def assert_no_overwrite(
29+
call: Callable[..., _Ignored], shapes: Iterable[tuple[int, ...]], dtypes: Iterable[type[np.generic]] | None = None
30+
) -> None: ... # undocumented

0 commit comments

Comments
 (0)