@@ -3,15 +3,25 @@ from typing import Final, Literal, TypeAlias, TypeVar, overload
33
44import numpy as np
55import optype .numpy as onp
6+ import optype .numpy .compat as npc
67
7- from scipy .sparse ._base import _spbase
8+ from scipy .sparse ._base import _SpMatrix , _SpArray2D
89from scipy .sparse .linalg import LinearOperator
910
1011__all__ = ["ArpackError" , "ArpackNoConvergence" , "eigs" , "eigsh" ]
1112
1213_KT = TypeVar ("_KT" )
14+ _SCT = TypeVar ("_SCT" , bound = _Numeric , default = _Numeric )
1315
14- _ToComplexMatrix : TypeAlias = onp .ToComplex2D | LinearOperator | _spbase
16+ _Numeric : TypeAlias = npc .number | np .bool_
17+ _ToFloat : TypeAlias = npc .floating | npc .integer | np .bool_
18+ _ToJustComplex : TypeAlias = npc .complexfloating
19+
20+ _Sparse2D : TypeAlias = _SpMatrix [_SCT ] | _SpArray2D [_SCT ]
21+
22+ _ToRealMatrix : TypeAlias = onp .ToFloat2D | _Sparse2D [_ToFloat ] | LinearOperator [_ToFloat ]
23+ _ToJustComplexMatrix : TypeAlias = onp .ToJustComplex2D | _Sparse2D [_ToJustComplex ] | LinearOperator [_ToJustComplex ]
24+ _ToComplexMatrix : TypeAlias = onp .ToComplex2D | _Sparse2D | LinearOperator
1525
1626_Which_eigs : TypeAlias = Literal ["LM" , "SM" , "LR" , "SR" , "LI" , "SI" ]
1727_Which_eigsh : TypeAlias = Literal ["LM" , "SM" , "LA" , "SA" , "BE" ]
@@ -86,7 +96,39 @@ def eigs(
8696) -> onp .Array1D [np .complex128 ]: ...
8797
8898#
89- @overload # returns_eigenvectors: truthy (default)
99+ @overload # real, returns_eigenvectors: truthy (default)
100+ def eigsh (
101+ A : _ToRealMatrix ,
102+ k : int = 6 ,
103+ M : _ToRealMatrix | None = None ,
104+ sigma : onp .ToFloat | None = None ,
105+ which : _Which_eigsh = "LM" ,
106+ v0 : onp .ToFloat1D | None = None ,
107+ ncv : int | None = None ,
108+ maxiter : int | None = None ,
109+ tol : float = 0 ,
110+ return_eigenvectors : onp .ToTrue = True ,
111+ Minv : _ToRealMatrix | None = None ,
112+ OPinv : _ToRealMatrix | None = None ,
113+ mode : _Mode = "normal" ,
114+ ) -> tuple [onp .Array1D [np .float64 ], onp .Array2D [np .float64 ]]: ...
115+ @overload # complex, returns_eigenvectors: truthy (default)
116+ def eigsh (
117+ A : _ToJustComplexMatrix ,
118+ k : int = 6 ,
119+ M : _ToComplexMatrix | None = None ,
120+ sigma : onp .ToFloat | None = None ,
121+ which : _Which_eigsh = "LM" ,
122+ v0 : onp .ToComplex1D | None = None ,
123+ ncv : int | None = None ,
124+ maxiter : int | None = None ,
125+ tol : float = 0 ,
126+ return_eigenvectors : onp .ToTrue = True ,
127+ Minv : _ToComplexMatrix | None = None ,
128+ OPinv : _ToComplexMatrix | None = None ,
129+ mode : _Mode = "normal" ,
130+ ) -> tuple [onp .Array1D [np .float64 ], onp .Array2D [np .complex128 ]]: ...
131+ @overload # real or complex (catch-all), returns_eigenvectors: truthy (default)
90132def eigsh (
91133 A : _ToComplexMatrix ,
92134 k : int = 6 ,
@@ -102,7 +144,7 @@ def eigsh(
102144 OPinv : _ToComplexMatrix | None = None ,
103145 mode : _Mode = "normal" ,
104146) -> tuple [onp .Array1D [np .float64 ], onp .Array2D [np .float64 | np .complex128 ]]: ...
105- @overload # returns_eigenvectors: falsy (positional)
147+ @overload # real or complex, returns_eigenvectors: falsy (positional)
106148def eigsh (
107149 A : _ToComplexMatrix ,
108150 k : int ,
@@ -118,7 +160,7 @@ def eigsh(
118160 OPinv : _ToComplexMatrix | None = None ,
119161 mode : _Mode = "normal" ,
120162) -> onp .Array1D [np .float64 ]: ...
121- @overload # returns_eigenvectors: falsy (keyword)
163+ @overload # real or complex, returns_eigenvectors: falsy (keyword)
122164def eigsh (
123165 A : _ToComplexMatrix ,
124166 k : int = 6 ,
0 commit comments