Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
_user_array_impl.pyi227 linesDownload Raw Back to lib
1from _typeshed import Incomplete
2from types import EllipsisType
3from typing import Any, Generic, Self, SupportsIndex, TypeAlias, overload
4from typing_extensions import TypeVar, deprecated, override
5
6import numpy as np
7import numpy.typing as npt
8from numpy._typing import (
9    _AnyShape,
10    _ArrayLike,
11    _ArrayLikeBool_co,
12    _ArrayLikeInt_co,
13    _DTypeLike,
14)
15
16###
17
18_ScalarT = TypeVar("_ScalarT", bound=np.generic)
19_ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
20_ShapeT_co = TypeVar("_ShapeT_co", bound=tuple[int, ...], default=_AnyShape, covariant=True)
21_DTypeT = TypeVar("_DTypeT", bound=np.dtype)
22_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype, default=np.dtype, covariant=True)
23
24_BoolArrayT = TypeVar("_BoolArrayT", bound=container[Any, np.dtype[np.bool]])
25_IntegralArrayT = TypeVar("_IntegralArrayT", bound=container[Any, np.dtype[np.bool | np.integer | np.object_]])
26_RealContainerT = TypeVar(
27    "_RealContainerT",
28    bound=container[Any, np.dtype[np.bool | np.integer | np.floating | np.timedelta64 | np.object_]],
29)
30_NumericContainerT = TypeVar("_NumericContainerT", bound=container[Any, np.dtype[np.number | np.timedelta64 | np.object_]])
31
32_ArrayInt_co: TypeAlias = npt.NDArray[np.integer | np.bool]
33
34_ToIndexSlice: TypeAlias = slice | EllipsisType | _ArrayInt_co | None
35_ToIndexSlices: TypeAlias = _ToIndexSlice | tuple[_ToIndexSlice, ...]
36_ToIndex: TypeAlias = SupportsIndex | _ToIndexSlice
37_ToIndices: TypeAlias = _ToIndex | tuple[_ToIndex, ...]
38
39###
40# pyright: reportDeprecated = false
41
42@deprecated("The numpy.lib.user_array.container class is deprecated and will be removed in a future version.")
43class container(Generic[_ShapeT_co, _DTypeT_co]):
44    array: np.ndarray[_ShapeT_co, _DTypeT_co]
45
46    @overload
47    def __init__(
48        self,
49        /,
50        data: container[_ShapeT_co, _DTypeT_co] | np.ndarray[_ShapeT_co, _DTypeT_co],
51        dtype: None = None,
52        copy: bool = True,
53    ) -> None: ...
54    @overload
55    def __init__(
56        self: container[Any, np.dtype[_ScalarT]],
57        /,
58        data: _ArrayLike[_ScalarT],
59        dtype: None = None,
60        copy: bool = True,
61    ) -> None: ...
62    @overload
63    def __init__(
64        self: container[Any, np.dtype[_ScalarT]],
65        /,
66        data: npt.ArrayLike,
67        dtype: _DTypeLike[_ScalarT],
68        copy: bool = True,
69    ) -> None: ...
70    @overload
71    def __init__(self, /, data: npt.ArrayLike, dtype: npt.DTypeLike | None = None, copy: bool = True) -> None: ...
72
73    #
74    def __complex__(self, /) -> complex: ...
75    def __float__(self, /) -> float: ...
76    def __int__(self, /) -> int: ...
77    def __hex__(self, /) -> str: ...
78    def __oct__(self, /) -> str: ...
79
80    #
81    @override
82    def __eq__(self, other: object, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...  # type: ignore[override]  # pyright: ignore[reportIncompatibleMethodOverride]
83    @override
84    def __ne__(self, other: object, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...  # type: ignore[override]  # pyright: ignore[reportIncompatibleMethodOverride]
85
86    #
87    def __lt__(self, other: npt.ArrayLike, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...
88    def __le__(self, other: npt.ArrayLike, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...
89    def __gt__(self, other: npt.ArrayLike, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...
90    def __ge__(self, other: npt.ArrayLike, /) -> container[_ShapeT_co, np.dtype[np.bool]]: ...
91
92    #
93    def __len__(self, /) -> int: ...
94
95    # keep in sync with np.ndarray
96    @overload
97    def __getitem__(self, key: _ArrayInt_co | tuple[_ArrayInt_co, ...], /) -> container[_ShapeT_co, _DTypeT_co]: ...
98    @overload
99    def __getitem__(self, key: _ToIndexSlices, /) -> container[_AnyShape, _DTypeT_co]: ...
100    @overload
101    def __getitem__(self, key: _ToIndices, /) -> Any: ...
102    @overload
103    def __getitem__(self: container[Any, np.dtype[np.void]], key: list[str], /) -> container[_ShapeT_co, np.dtype[np.void]]: ...
104    @overload
105    def __getitem__(self: container[Any, np.dtype[np.void]], key: str, /) -> container[_ShapeT_co, np.dtype]: ...
106
107    # keep in sync with np.ndarray
108    @overload
109    def __setitem__(self, index: _ToIndices, value: object, /) -> None: ...
110    @overload
111    def __setitem__(self: container[Any, np.dtype[np.void]], key: str | list[str], value: object, /) -> None: ...
112
113    # keep in sync with np.ndarray
114    @overload
115    def __abs__(self: container[_ShapeT, np.dtype[np.complex64]], /) -> container[_ShapeT, np.dtype[np.float32]]: ...  # type: ignore[overload-overlap]
116    @overload
117    def __abs__(self: container[_ShapeT, np.dtype[np.complex128]], /) -> container[_ShapeT, np.dtype[np.float64]]: ...
118    @overload
119    def __abs__(self: container[_ShapeT, np.dtype[np.complex192]], /) -> container[_ShapeT, np.dtype[np.float96]]: ...
120    @overload
121    def __abs__(self: container[_ShapeT, np.dtype[np.complex256]], /) -> container[_ShapeT, np.dtype[np.float128]]: ...
122    @overload
123    def __abs__(self: _RealContainerT, /) -> _RealContainerT: ...
124
125    #
126    def __neg__(self: _NumericContainerT, /) -> _NumericContainerT: ...  # noqa: PYI019
127    def __pos__(self: _NumericContainerT, /) -> _NumericContainerT: ...  # noqa: PYI019
128    def __invert__(self: _IntegralArrayT, /) -> _IntegralArrayT: ...  # noqa: PYI019
129
130    # TODO(jorenham): complete these binary ops
131
132    #
133    def __add__(self, other: npt.ArrayLike, /) -> Incomplete: ...
134    def __radd__(self, other: npt.ArrayLike, /) -> Incomplete: ...
135    def __iadd__(self, other: npt.ArrayLike, /) -> Self: ...
136
137    #
138    def __sub__(self, other: npt.ArrayLike, /) -> Incomplete: ...
139    def __rsub__(self, other: npt.ArrayLike, /) -> Incomplete: ...
140    def __isub__(self, other: npt.ArrayLike, /) -> Self: ...
141
142    #
143    def __mul__(self, other: npt.ArrayLike, /) -> Incomplete: ...
144    def __rmul__(self, other: npt.ArrayLike, /) -> Incomplete: ...
145    def __imul__(self, other: npt.ArrayLike, /) -> Self: ...
146
147    #
148    def __mod__(self, other: npt.ArrayLike, /) -> Incomplete: ...
149    def __rmod__(self, other: npt.ArrayLike, /) -> Incomplete: ...
150    def __imod__(self, other: npt.ArrayLike, /) -> Self: ...
151
152    #
153    def __divmod__(self, other: npt.ArrayLike, /) -> tuple[Incomplete, Incomplete]: ...
154    def __rdivmod__(self, other: npt.ArrayLike, /) -> tuple[Incomplete, Incomplete]: ...
155
156    #
157    def __pow__(self, other: npt.ArrayLike, /) -> Incomplete: ...
158    def __rpow__(self, other: npt.ArrayLike, /) -> Incomplete: ...
159    def __ipow__(self, other: npt.ArrayLike, /) -> Self: ...
160
161    #
162    def __lshift__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.integer]]: ...
163    def __rlshift__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.integer]]: ...
164    def __ilshift__(self, other: _ArrayLikeInt_co, /) -> Self: ...
165
166    #
167    def __rshift__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.integer]]: ...
168    def __rrshift__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.integer]]: ...
169    def __irshift__(self, other: _ArrayLikeInt_co, /) -> Self: ...
170
171    #
172    @overload
173    def __and__(
174        self: container[Any, np.dtype[np.bool]], other: _ArrayLikeBool_co, /
175    ) -> container[_AnyShape, np.dtype[np.bool]]: ...
176    @overload
177    def __and__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.bool | np.integer]]: ...
178    __rand__ = __and__
179    @overload
180    def __iand__(self: _BoolArrayT, other: _ArrayLikeBool_co, /) -> _BoolArrayT: ...
181    @overload
182    def __iand__(self, other: _ArrayLikeInt_co, /) -> Self: ...
183
184    #
185    @overload
186    def __xor__(
187        self: container[Any, np.dtype[np.bool]], other: _ArrayLikeBool_co, /
188    ) -> container[_AnyShape, np.dtype[np.bool]]: ...
189    @overload
190    def __xor__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.bool | np.integer]]: ...
191    __rxor__ = __xor__
192    @overload
193    def __ixor__(self: _BoolArrayT, other: _ArrayLikeBool_co, /) -> _BoolArrayT: ...
194    @overload
195    def __ixor__(self, other: _ArrayLikeInt_co, /) -> Self: ...
196
197    #
198    @overload
199    def __or__(
200        self: container[Any, np.dtype[np.bool]], other: _ArrayLikeBool_co, /
201    ) -> container[_AnyShape, np.dtype[np.bool]]: ...
202    @overload
203    def __or__(self, other: _ArrayLikeInt_co, /) -> container[_AnyShape, np.dtype[np.bool | np.integer]]: ...
204    __ror__ = __or__
205    @overload
206    def __ior__(self: _BoolArrayT, other: _ArrayLikeBool_co, /) -> _BoolArrayT: ...
207    @overload
208    def __ior__(self, other: _ArrayLikeInt_co, /) -> Self: ...
209
210    #
211    @overload
212    def __array__(self, /, t: None = None) -> np.ndarray[_ShapeT_co, _DTypeT_co]: ...
213    @overload
214    def __array__(self, /, t: _DTypeT) -> np.ndarray[_ShapeT_co, _DTypeT]: ...
215
216    #
217    @overload
218    def __array_wrap__(self, arg0: npt.ArrayLike, /) -> container[_ShapeT_co, _DTypeT_co]: ...
219    @overload
220    def __array_wrap__(self, a: np.ndarray[_ShapeT, _DTypeT], c: Any = ..., s: Any = ..., /) -> container[_ShapeT, _DTypeT]: ...
221
222    #
223    def copy(self, /) -> Self: ...
224    def tobytes(self, /) -> bytes: ...
225    def byteswap(self, /) -> Self: ...
226    def astype(self, /, typecode: _DTypeLike[_ScalarT]) -> container[_ShapeT_co, np.dtype[_ScalarT]]: ...
227 
codekingpro/portable-devtools · Team Ai