@@ -2,8 +2,8 @@ from collections.abc import Callable
22from typing import Any , Literal , TypeAlias , overload
33
44import numpy as np
5- import numpy .typing as npt
65import optype .numpy as onp
6+ import optype .typing as opt
77from ._expm_frechet import expm_cond , expm_frechet
88from ._matfuncs_sqrtm import sqrtm
99
@@ -25,35 +25,107 @@ __all__ = [
2525 "tanm" ,
2626]
2727
28- _Array_fc_2d : TypeAlias = onp .Array2D [np .inexact [Any ]]
29- _Array_fc_nd : TypeAlias = onp .ArrayND [np .inexact [Any ]]
30-
31- def fractional_matrix_power (A : npt .ArrayLike , t : float ) -> _Array_fc_2d : ...
32- @overload
33- def logm (A : npt .ArrayLike , disp : Literal [True ] = True ) -> _Array_fc_2d : ...
34- @overload
35- def logm (A : npt .ArrayLike , disp : Literal [False ]) -> tuple [_Array_fc_2d , float | np .float64 ]: ...
36- def expm (A : npt .ArrayLike ) -> onp .ArrayND [np .inexact [Any ]]: ...
37- def cosm (A : npt .ArrayLike ) -> _Array_fc_2d : ...
38- def sinm (A : npt .ArrayLike ) -> _Array_fc_2d : ...
39- def tanm (A : npt .ArrayLike ) -> _Array_fc_2d : ...
40- def coshm (A : npt .ArrayLike ) -> _Array_fc_2d : ...
41- def sinhm (A : npt .ArrayLike ) -> _Array_fc_2d : ...
42- def tanhm (A : npt .ArrayLike ) -> _Array_fc_2d : ...
43- @overload
44- def funm (
45- A : npt .ArrayLike ,
46- func : Callable [[_Array_fc_nd ], _Array_fc_nd ],
47- disp : Literal [True , 1 ] = True ,
48- ) -> _Array_fc_2d : ...
49- @overload
50- def funm (
51- A : npt .ArrayLike ,
52- func : Callable [[_Array_fc_nd ], _Array_fc_nd ],
53- disp : Literal [False , 0 ],
54- ) -> tuple [_Array_fc_2d , float | np .float64 ]: ...
55- @overload
56- def signm (A : npt .ArrayLike , disp : Literal [True ] = True ) -> _Array_fc_2d : ...
57- @overload
58- def signm (A : npt .ArrayLike , disp : Literal [False ]) -> tuple [_Array_fc_2d , float | np .float64 ]: ...
59- def khatri_rao (a : npt .ArrayLike , b : npt .ArrayLike ) -> _Array_fc_2d : ...
28+ _ToPosInt : TypeAlias = np .unsignedinteger [Any ] | Literal [0 , 1 , 2 , 4 , 5 , 6 , 7 , 8 ]
29+
30+ _Int2D : TypeAlias = onp .Array2D [np .integer [Any ]]
31+ _Complex2D : TypeAlias = onp .Array2D [np .complexfloating [Any , Any ]]
32+ _Real2D : TypeAlias = onp .Array2D [np .floating [Any ] | np .integer [Any ]]
33+ _Numeric2D : TypeAlias = onp .Array2D [np .number [Any ]]
34+ _Float2D : TypeAlias = onp .Array2D [np .floating [Any ]]
35+ _Inexact2D : TypeAlias = onp .Array2D [np .inexact [Any ]]
36+
37+ _FloatND : TypeAlias = onp .ArrayND [np .floating [Any ]]
38+ _InexactND : TypeAlias = onp .ArrayND [np .inexact [Any ]]
39+
40+ _Falsy : TypeAlias = Literal [False , 0 ]
41+ _Truthy : TypeAlias = Literal [True , 1 ]
42+
43+ _FloatFunc : TypeAlias = Callable [[onp .Array1D [np .float64 ]], onp .ToFloat1D ]
44+ _ComplexFunc : TypeAlias = Callable [[onp .Array1D [np .complex128 ]], onp .ToComplex1D ]
45+
46+ ###
47+
48+ @overload # int, positive int
49+ def fractional_matrix_power (A : onp .ToInt2D , t : _ToPosInt ) -> _Int2D : ... # pyright: ignore[reportOverlappingOverload] # pyright<1.390 bug
50+ @overload # real, int
51+ def fractional_matrix_power (A : onp .ToFloat2D , t : onp .ToInt ) -> _Real2D : ...
52+ @overload # complex, int
53+ def fractional_matrix_power (A : onp .ToComplex2D , t : onp .ToInt ) -> _Numeric2D : ...
54+ @overload # complex, float
55+ def fractional_matrix_power (A : onp .ToComplex2D , t : opt .Just [float ] | np .floating [Any ]) -> _Complex2D : ...
56+
57+ # NOTE: return dtype depends on the sign of the values
58+ @overload # disp: True = ...
59+ def logm (A : onp .ToComplex2D , disp : _Truthy = True ) -> _Inexact2D : ...
60+ @overload # disp: False
61+ def logm (A : onp .ToComplex2D , disp : _Falsy ) -> tuple [_Inexact2D , float ]: ...
62+
63+ #
64+ @overload # real
65+ def expm (A : onp .ToFloatND ) -> _FloatND : ...
66+ @overload # complex
67+ def expm (A : onp .ToComplexND ) -> _InexactND : ...
68+
69+ #
70+ @overload # real
71+ def cosm (A : onp .ToFloat2D ) -> _Float2D : ...
72+ @overload # complex
73+ def cosm (A : onp .ToComplex2D ) -> _Inexact2D : ...
74+
75+ #
76+ @overload # real
77+ def sinm (A : onp .ToFloat2D ) -> _Float2D : ...
78+ @overload # complex
79+ def sinm (A : onp .ToComplex2D ) -> _Inexact2D : ...
80+
81+ #
82+ @overload # real
83+ def tanm (A : onp .ToFloat2D ) -> _Float2D : ...
84+ @overload # complex
85+ def tanm (A : onp .ToComplex2D ) -> _Inexact2D : ...
86+
87+ #
88+ @overload # real
89+ def coshm (A : onp .ToFloat2D ) -> _Float2D : ...
90+ @overload # complex
91+ def coshm (A : onp .ToComplex2D ) -> _Inexact2D : ...
92+
93+ #
94+ @overload # real
95+ def sinhm (A : onp .ToFloat2D ) -> _Float2D : ...
96+ @overload # complex
97+ def sinhm (A : onp .ToComplex2D ) -> _Inexact2D : ...
98+
99+ #
100+ @overload # real
101+ def tanhm (A : onp .ToFloat2D ) -> _Float2D : ...
102+ @overload # complex
103+ def tanhm (A : onp .ToComplex2D ) -> _Inexact2D : ...
104+
105+ #
106+ @overload # real, disp: True = ...
107+ def funm (A : onp .ToFloat2D , func : _FloatFunc , disp : _Truthy = True ) -> _Float2D : ...
108+ @overload # real, disp: False
109+ def funm (A : onp .ToFloat2D , func : _FloatFunc , disp : _Falsy ) -> _Complex2D : ...
110+ @overload # complex, disp: True = ...
111+ def funm (A : onp .ToComplex2D , func : _ComplexFunc , disp : _Truthy = True ) -> _Complex2D : ...
112+ @overload # complex, disp: False
113+ def funm (A : onp .ToComplex2D , func : _ComplexFunc , disp : _Falsy ) -> tuple [_Complex2D , np .float64 ]: ...
114+
115+ #
116+ @overload # real, disp: True = ...
117+ def signm (A : onp .ToFloat2D , disp : _Truthy = True ) -> _Float2D : ...
118+ @overload # real, disp: False
119+ def signm (A : onp .ToFloat2D , disp : _Falsy ) -> tuple [_Float2D , np .float64 ]: ...
120+ @overload # complex, disp: True = ...
121+ def signm (A : onp .ToComplex2D , disp : _Truthy = True ) -> _Inexact2D : ...
122+ @overload # complex, disp: False
123+ def signm (A : onp .ToComplex2D , disp : _Falsy ) -> tuple [_Inexact2D , np .float64 ]: ...
124+
125+ #
126+ @overload # int
127+ def khatri_rao (a : onp .ToInt2D , b : onp .ToInt2D ) -> _Int2D : ...
128+ @overload # real
129+ def khatri_rao (a : onp .ToFloat2D , b : onp .ToFloat2D ) -> _Real2D : ...
130+ @overload # complex
131+ def khatri_rao (a : onp .ToComplex2D , b : onp .ToComplex2D ) -> _Numeric2D : ...
0 commit comments