11from typing import Literal , TypeAlias , overload
2+ from typing_extensions import TypeVar
23
34import numpy as np
45import numpy .typing as npt
6+ import optype .numpy as onpt
57import scipy ._typing as spt
68
79__all__ = [
@@ -24,42 +26,43 @@ __all__ = [
2426 "toeplitz" ,
2527]
2628
27- _Array_2d : TypeAlias = np .ndarray [tuple [int , int ], np .dtype [np .generic ]]
28- _Array_O_2d : TypeAlias = np .ndarray [tuple [int , int ], np .dtypes .ObjectDType ]
29- _Array_u8_2d : TypeAlias = np .ndarray [tuple [int , int ], np .dtypes .UInt64DType ]
30- _Array_i8_2d : TypeAlias = np .ndarray [tuple [int , int ], np .dtypes .Int64DType ]
31- _Array_f8_2d : TypeAlias = np .ndarray [tuple [int , int ], np .dtypes .Float64DType ]
32- _Array_c16_2d : TypeAlias = np .ndarray [tuple [int , int ], np .dtypes .Complex128DType ]
29+ _SCT = TypeVar ("_SCT" , bound = np .generic , default = np .generic )
3330
34- _SymmetryKind : TypeAlias = Literal ["symmetric" , "upper" , "lower" ]
31+ _Matrix : TypeAlias = onpt .Array [tuple [int , int ], _SCT ]
32+ _Kind : TypeAlias = Literal ["symmetric" , "upper" , "lower" ]
3533
36- def toeplitz (c : npt .ArrayLike , r : npt .ArrayLike | None = None ) -> _Array_2d : ...
37- def circulant (c : npt .ArrayLike ) -> _Array_2d : ...
38- def hankel (c : npt .ArrayLike , r : npt .ArrayLike | None = None ) -> _Array_2d : ...
39- def hadamard (n : spt .AnyInt , dtype : npt .DTypeLike = ...) -> _Array_2d : ...
40- def leslie (f : npt .ArrayLike , s : npt .ArrayLike ) -> _Array_2d : ...
41- def kron (a : npt .ArrayLike , b : npt .ArrayLike ) -> _Array_2d : ...
42- def block_diag (* arrs : npt .ArrayLike ) -> _Array_2d : ...
43- def companion (a : npt .ArrayLike ) -> _Array_2d : ...
44- def helmert (n : spt .AnyInt , full : bool = False ) -> _Array_f8_2d : ...
45- def hilbert (n : spt .AnyInt ) -> _Array_f8_2d : ...
34+ ###
35+
36+ # TODO(jorenham): transparent dtypes
37+ def toeplitz (c : npt .ArrayLike , r : npt .ArrayLike | None = None ) -> _Matrix : ...
38+ def circulant (c : npt .ArrayLike ) -> _Matrix : ...
39+ def hankel (c : npt .ArrayLike , r : npt .ArrayLike | None = None ) -> _Matrix : ...
40+ def hadamard (n : spt .AnyInt , dtype : npt .DTypeLike = ...) -> _Matrix : ...
41+ def leslie (f : npt .ArrayLike , s : npt .ArrayLike ) -> _Matrix : ...
42+ def kron (a : npt .ArrayLike , b : npt .ArrayLike ) -> _Matrix : ...
43+ def block_diag (* arrs : npt .ArrayLike ) -> _Matrix : ...
44+ def companion (a : npt .ArrayLike ) -> _Matrix : ...
45+ def helmert (n : spt .AnyInt , full : bool = False ) -> _Matrix [np .float64 ]: ...
46+ def hilbert (n : spt .AnyInt ) -> _Matrix [np .float64 ]: ...
47+ def fiedler (a : npt .ArrayLike ) -> _Matrix : ...
48+ def fiedler_companion (a : npt .ArrayLike ) -> _Matrix : ...
49+ def convolution_matrix (a : npt .ArrayLike , n : spt .AnyInt , mode : spt .CorrelateMode = "full" ) -> _Matrix : ...
50+
51+ #
4652@overload
47- def invhilbert (n : spt .AnyInt , exact : Literal [False ] = False ) -> _Array_f8_2d : ...
53+ def invhilbert (n : spt .AnyInt , exact : Literal [False ] = False ) -> _Matrix [ np . float64 ] : ...
4854@overload
49- def invhilbert (n : spt .AnyInt , exact : Literal [True ]) -> _Array_i8_2d | _Array_O_2d : ...
55+ def invhilbert (n : spt .AnyInt , exact : Literal [True ]) -> _Matrix [ np . int64 ] | _Matrix [ np . object_ ] : ...
5056@overload
51- def pascal (n : spt .AnyInt , kind : _SymmetryKind = "symmetric" , exact : Literal [True ] = True ) -> _Array_u8_2d | _Array_O_2d : ...
57+ def pascal (n : spt .AnyInt , kind : _Kind = "symmetric" , exact : Literal [True ] = True ) -> _Matrix [ np . uint64 | np . object_ ] : ...
5258@overload
53- def pascal (n : spt .AnyInt , kind : _SymmetryKind = "symmetric" , * , exact : Literal [False ]) -> _Array_f8_2d : ...
59+ def pascal (n : spt .AnyInt , kind : _Kind = "symmetric" , * , exact : Literal [False ]) -> _Matrix [ np . float64 ] : ...
5460@overload
55- def pascal (n : spt .AnyInt , kind : _SymmetryKind , exact : Literal [False ]) -> _Array_f8_2d : ...
61+ def pascal (n : spt .AnyInt , kind : _Kind , exact : Literal [False ]) -> _Matrix [ np . float64 ] : ...
5662@overload
57- def invpascal (n : spt .AnyInt , kind : _SymmetryKind = "symmetric" , exact : Literal [True ] = True ) -> _Array_i8_2d | _Array_O_2d : ...
63+ def invpascal (n : spt .AnyInt , kind : _Kind = "symmetric" , exact : Literal [True ] = True ) -> _Matrix [ np . int64 | np . object_ ] : ...
5864@overload
59- def invpascal (n : spt .AnyInt , kind : _SymmetryKind = "symmetric" , * , exact : Literal [False ]) -> _Array_f8_2d : ...
65+ def invpascal (n : spt .AnyInt , kind : _Kind = "symmetric" , * , exact : Literal [False ]) -> _Matrix [ np . float64 ] : ...
6066@overload
61- def invpascal (n : spt .AnyInt , kind : _SymmetryKind , exact : Literal [False ]) -> _Array_f8_2d : ...
62- def dft (n : spt .AnyInt , scale : Literal ["sqrtn" , "n" ] | None = None ) -> _Array_c16_2d : ...
63- def fiedler (a : npt .ArrayLike ) -> _Array_2d : ...
64- def fiedler_companion (a : npt .ArrayLike ) -> _Array_2d : ...
65- def convolution_matrix (a : npt .ArrayLike , n : spt .AnyInt , mode : spt .CorrelateMode = "full" ) -> _Array_2d : ...
67+ def invpascal (n : spt .AnyInt , kind : _Kind , exact : Literal [False ]) -> _Matrix [np .float64 ]: ...
68+ def dft (n : spt .AnyInt , scale : Literal ["sqrtn" , "n" ] | None = None ) -> _Matrix [np .complex128 ]: ...
0 commit comments