Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
defmatrix.pyi219 linesDownload Raw Back to matrixlib
1from _typeshed import Incomplete
2from collections.abc import Mapping, Sequence
3from types import EllipsisType
4from typing import Any, ClassVar, Literal as L, Self, SupportsIndex, TypeAlias, overload
5from typing_extensions import TypeVar
6
7import numpy as np
8from numpy._typing import (
9    ArrayLike,
10    DTypeLike,
11    NDArray,
12    _AnyShape,
13    _ArrayLikeInt_co,
14    _NestedSequence,
15    _ShapeLike,
16)
17
18__all__ = ["asmatrix", "bmat", "matrix"]
19
20_T = TypeVar("_T")
21_ArrayT = TypeVar("_ArrayT", bound=np.ndarray)
22_BoolOrIntArrayT = TypeVar("_BoolOrIntArrayT", bound=NDArray[np.integer | np.bool])
23_ScalarT = TypeVar("_ScalarT", bound=np.generic)
24_ShapeT_co = TypeVar("_ShapeT_co", bound=_2D, default=_2D, covariant=True)
25_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype, default=np.dtype, covariant=True)
26
27_2D: TypeAlias = tuple[int, int]
28_Matrix: TypeAlias = matrix[_2D, np.dtype[_ScalarT]]
29_ToIndex1: TypeAlias = slice | EllipsisType | NDArray[np.integer | np.bool] | _NestedSequence[int] | None
30_ToIndex2: TypeAlias = tuple[_ToIndex1, _ToIndex1 | SupportsIndex] | tuple[_ToIndex1 | SupportsIndex, _ToIndex1]
31
32class matrix(np.ndarray[_ShapeT_co, _DTypeT_co]):
33    __array_priority__: ClassVar[float] = 10.0  # pyright: ignore[reportIncompatibleMethodOverride]
34
35    def __new__(
36        subtype,  # pyright: ignore[reportSelfClsParameterName]
37        data: ArrayLike,
38        dtype: DTypeLike | None = None,
39        copy: bool = True,
40    ) -> _Matrix[Incomplete]: ...
41
42    #
43    @overload  # type: ignore[override]
44    def __getitem__(
45        self, key: SupportsIndex | _ArrayLikeInt_co | tuple[SupportsIndex | _ArrayLikeInt_co, ...], /
46    ) -> Incomplete: ...
47    @overload
48    def __getitem__(self, key: _ToIndex1 | _ToIndex2, /) -> matrix[_2D, _DTypeT_co]: ...
49    @overload
50    def __getitem__(self: _Matrix[np.void], key: str, /) -> _Matrix[Incomplete]: ...
51    @overload
52    def __getitem__(self: _Matrix[np.void], key: list[str], /) -> matrix[_2D, _DTypeT_co]: ...  # pyright: ignore[reportIncompatibleMethodOverride]
53
54    #
55    def __mul__(self, other: ArrayLike, /) -> _Matrix[Incomplete]: ...  # type: ignore[override]  # pyright: ignore[reportIncompatibleMethodOverride]
56    def __rmul__(self, other: ArrayLike, /) -> _Matrix[Incomplete]: ...  # type: ignore[override]  # pyright: ignore[reportIncompatibleMethodOverride]
57
58    #
59    def __pow__(self, other: ArrayLike, /) -> _Matrix[Incomplete]: ...  # type: ignore[override]  # pyright: ignore[reportIncompatibleMethodOverride]
60    def __rpow__(self, other: ArrayLike, /) -> _Matrix[Incomplete]: ...  # type: ignore[override]  # pyright: ignore[reportIncompatibleMethodOverride]
61
62    # keep in sync with `prod` and `mean`
63    @overload  # type: ignore[override]
64    def sum(self, axis: None = None, dtype: DTypeLike | None = None, out: None = None) -> Incomplete: ...
65    @overload
66    def sum(self, axis: _ShapeLike, dtype: DTypeLike | None = None, out: None = None) -> _Matrix[Incomplete]: ...
67    @overload
68    def sum(self, axis: _ShapeLike | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ...
69    @overload
70    def sum(self, axis: _ShapeLike | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
71
72    # keep in sync with `sum` and `mean`
73    @overload  # type: ignore[override]
74    def prod(self, axis: None = None, dtype: DTypeLike | None = None, out: None = None) -> Incomplete: ...
75    @overload
76    def prod(self, axis: _ShapeLike, dtype: DTypeLike | None = None, out: None = None) -> _Matrix[Incomplete]: ...
77    @overload
78    def prod(self, axis: _ShapeLike | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ...
79    @overload
80    def prod(self, axis: _ShapeLike | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
81
82    # keep in sync with `sum` and `prod`
83    @overload  # type: ignore[override]
84    def mean(self, axis: None = None, dtype: DTypeLike | None = None, out: None = None) -> Incomplete: ...
85    @overload
86    def mean(self, axis: _ShapeLike, dtype: DTypeLike | None = None, out: None = None) -> _Matrix[Incomplete]: ...
87    @overload
88    def mean(self, axis: _ShapeLike | None, dtype: DTypeLike | None, out: _ArrayT) -> _ArrayT: ...
89    @overload
90    def mean(self, axis: _ShapeLike | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
91
92    # keep in sync with `var`
93    @overload  # type: ignore[override]
94    def std(self, axis: None = None, dtype: DTypeLike | None = None, out: None = None, ddof: float = 0) -> Incomplete: ...
95    @overload
96    def std(self, axis: _ShapeLike, dtype: DTypeLike | None = None, out: None = None, ddof: float = 0) -> _Matrix[Incomplete]: ...
97    @overload
98    def std(self, axis: _ShapeLike | None, dtype: DTypeLike | None, out: _ArrayT, ddof: float = 0) -> _ArrayT: ...
99    @overload
100    def std(  # pyright: ignore[reportIncompatibleMethodOverride]
101        self, axis: _ShapeLike | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT, ddof: float = 0
102    ) -> _ArrayT: ...
103
104    # keep in sync with `std`
105    @overload  # type: ignore[override]
106    def var(self, axis: None = None, dtype: DTypeLike | None = None, out: None = None, ddof: float = 0) -> Incomplete: ...
107    @overload
108    def var(self, axis: _ShapeLike, dtype: DTypeLike | None = None, out: None = None, ddof: float = 0) -> _Matrix[Incomplete]: ...
109    @overload
110    def var(self, axis: _ShapeLike | None, dtype: DTypeLike | None, out: _ArrayT, ddof: float = 0) -> _ArrayT: ...
111    @overload
112    def var(  # pyright: ignore[reportIncompatibleMethodOverride]
113        self, axis: _ShapeLike | None = None, dtype: DTypeLike | None = None, *, out: _ArrayT, ddof: float = 0
114    ) -> _ArrayT: ...
115
116    # keep in sync with `all`
117    @overload  # type: ignore[override]
118    def any(self, axis: None = None, out: None = None) -> np.bool: ...
119    @overload
120    def any(self, axis: _ShapeLike, out: None = None) -> _Matrix[np.bool]: ...
121    @overload
122    def any(self, axis: _ShapeLike | None, out: _ArrayT) -> _ArrayT: ...
123    @overload
124    def any(self, axis: _ShapeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
125
126    # keep in sync with `any`
127    @overload  # type: ignore[override]
128    def all(self, axis: None = None, out: None = None) -> np.bool: ...
129    @overload
130    def all(self, axis: _ShapeLike, out: None = None) -> _Matrix[np.bool]: ...
131    @overload
132    def all(self, axis: _ShapeLike | None, out: _ArrayT) -> _ArrayT: ...
133    @overload
134    def all(self, axis: _ShapeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
135
136    # keep in sync with `min` and `ptp`
137    @overload  # type: ignore[override]
138    def max(self: NDArray[_ScalarT], axis: None = None, out: None = None) -> _ScalarT: ...
139    @overload
140    def max(self, axis: _ShapeLike, out: None = None) -> matrix[_2D, _DTypeT_co]: ...
141    @overload
142    def max(self, axis: _ShapeLike | None, out: _ArrayT) -> _ArrayT: ...
143    @overload
144    def max(self, axis: _ShapeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
145
146    # keep in sync with `max` and `ptp`
147    @overload  # type: ignore[override]
148    def min(self: NDArray[_ScalarT], axis: None = None, out: None = None) -> _ScalarT: ...
149    @overload
150    def min(self, axis: _ShapeLike, out: None = None) -> matrix[_2D, _DTypeT_co]: ...
151    @overload
152    def min(self, axis: _ShapeLike | None, out: _ArrayT) -> _ArrayT: ...
153    @overload
154    def min(self, axis: _ShapeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
155
156    # keep in sync with `max` and `min`
157    @overload
158    def ptp(self: NDArray[_ScalarT], axis: None = None, out: None = None) -> _ScalarT: ...
159    @overload
160    def ptp(self, axis: _ShapeLike, out: None = None) -> matrix[_2D, _DTypeT_co]: ...
161    @overload
162    def ptp(self, axis: _ShapeLike | None, out: _ArrayT) -> _ArrayT: ...
163    @overload
164    def ptp(self, axis: _ShapeLike | None = None, *, out: _ArrayT) -> _ArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
165
166    # keep in sync with `argmin`
167    @overload  # type: ignore[override]
168    def argmax(self: NDArray[_ScalarT], axis: None = None, out: None = None) -> np.intp: ...
169    @overload
170    def argmax(self, axis: _ShapeLike, out: None = None) -> _Matrix[np.intp]: ...
171    @overload
172    def argmax(self, axis: _ShapeLike | None, out: _BoolOrIntArrayT) -> _BoolOrIntArrayT: ...
173    @overload
174    def argmax(self, axis: _ShapeLike | None = None, *, out: _BoolOrIntArrayT) -> _BoolOrIntArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
175
176    # keep in sync with `argmax`
177    @overload  # type: ignore[override]
178    def argmin(self: NDArray[_ScalarT], axis: None = None, out: None = None) -> np.intp: ...
179    @overload
180    def argmin(self, axis: _ShapeLike, out: None = None) -> _Matrix[np.intp]: ...
181    @overload
182    def argmin(self, axis: _ShapeLike | None, out: _BoolOrIntArrayT) -> _BoolOrIntArrayT: ...
183    @overload
184    def argmin(self, axis: _ShapeLike | None = None, *, out: _BoolOrIntArrayT) -> _BoolOrIntArrayT: ...  # pyright: ignore[reportIncompatibleMethodOverride]
185
186    # the second overload handles the (rare) case that the matrix is not 2-d
187    @overload
188    def tolist(self: _Matrix[np.generic[_T]]) -> list[list[_T]]: ...  # pyright: ignore[reportIncompatibleMethodOverride]
189    @overload
190    def tolist(self) -> Incomplete: ...  # pyright: ignore[reportIncompatibleMethodOverride]
191
192    # these three methods will at least return a `2-d` array of shape (1, n)
193    def squeeze(self, /, axis: _ShapeLike | None = None) -> matrix[_2D, _DTypeT_co]: ...
194    def ravel(self, /, order: L["K", "A", "C", "F"] | None = "C") -> matrix[_2D, _DTypeT_co]: ...  # type: ignore[override]  # pyright: ignore[reportIncompatibleMethodOverride]
195    def flatten(self, /, order: L["K", "A", "C", "F"] | None = "C") -> matrix[_2D, _DTypeT_co]: ...  # type: ignore[override]  # pyright: ignore[reportIncompatibleMethodOverride]
196
197    # matrix.T is inherited from _ScalarOrArrayCommon
198    def getT(self) -> Self: ...
199    @property
200    def I(self) -> _Matrix[Incomplete]: ...  # noqa: E743
201    def getI(self) -> _Matrix[Incomplete]: ...
202    @property
203    def A(self) -> np.ndarray[_2D, _DTypeT_co]: ...
204    def getA(self) -> np.ndarray[_2D, _DTypeT_co]: ...
205    @property
206    def A1(self) -> np.ndarray[_AnyShape, _DTypeT_co]: ...
207    def getA1(self) -> np.ndarray[_AnyShape, _DTypeT_co]: ...
208    @property
209    def H(self) -> matrix[_2D, _DTypeT_co]: ...
210    def getH(self) -> matrix[_2D, _DTypeT_co]: ...
211
212def bmat(
213    obj: str | Sequence[ArrayLike] | NDArray[Any],
214    ldict: Mapping[str, Any] | None = None,
215    gdict: Mapping[str, Any] | None = None,
216) -> _Matrix[Incomplete]: ...
217
218def asmatrix(data: ArrayLike, dtype: DTypeLike | None = None) -> _Matrix[Incomplete]: ...
219 
codekingpro/portable-devtools · Team Ai