codekingpro/portable-devtools
114k
1import abc
2import decimal
3from collections.abc import Iterator, Sequence
4from typing import (
5 Any,
6 ClassVar,
7 Generic,
8 Literal,
9 Self,
10 SupportsIndex,
11 TypeAlias,
12 overload,
13)
14from typing_extensions import TypeIs, TypeVar
15
16import numpy as np
17import numpy.typing as npt
18from numpy._typing import (
19 _ArrayLikeComplex_co,
20 _ArrayLikeFloat_co,
21 _FloatLike_co,
22 _NumberLike_co,
23)
24
25from ._polytypes import (
26 _AnyInt,
27 _Array2,
28 _ArrayLikeCoef_co,
29 _ArrayLikeCoefObject_co,
30 _CoefLike_co,
31 _CoefSeries,
32 _Series,
33 _SeriesLikeCoef_co,
34 _SeriesLikeInt_co,
35 _Tuple2,
36)
37
38__all__ = ["ABCPolyBase"]
39
40_NameT_co = TypeVar("_NameT_co", bound=str | None, default=str | None, covariant=True)
41_PolyT = TypeVar("_PolyT", bound=ABCPolyBase)
42_AnyOther: TypeAlias = ABCPolyBase | _CoefLike_co | _SeriesLikeCoef_co
43
44class ABCPolyBase(Generic[_NameT_co], abc.ABC):
45 __hash__: ClassVar[None] = None # type: ignore[assignment] # pyright: ignore[reportIncompatibleMethodOverride]
46 __array_ufunc__: ClassVar[None] = None
47 maxpower: ClassVar[Literal[100]] = 100
48
49 _superscript_mapping: ClassVar[dict[int, str]] = ...
50 _subscript_mapping: ClassVar[dict[int, str]] = ...
51 _use_unicode: ClassVar[bool] = ...
52
53 _symbol: str
54 @property
55 def symbol(self, /) -> str: ...
56 @property
57 @abc.abstractmethod
58 def domain(self) -> _Array2[np.float64 | Any]: ...
59 @property
60 @abc.abstractmethod
61 def window(self) -> _Array2[np.float64 | Any]: ...
62 @property
63 @abc.abstractmethod
64 def basis_name(self) -> _NameT_co: ...
65
66 coef: _CoefSeries
67
68 def __init__(
69 self,
70 /,
71 coef: _SeriesLikeCoef_co,
72 domain: _SeriesLikeCoef_co | None = None,
73 window: _SeriesLikeCoef_co | None = None,
74 symbol: str = "x",
75 ) -> None: ...
76
77 #
78 @overload
79 def __call__(self, /, arg: _PolyT) -> _PolyT: ...
80 @overload
81 def __call__(self, /, arg: _FloatLike_co | decimal.Decimal) -> np.float64 | Any: ...
82 @overload
83 def __call__(self, /, arg: _NumberLike_co) -> np.complex128 | Any: ...
84 @overload
85 def __call__(self, /, arg: _ArrayLikeFloat_co) -> npt.NDArray[np.float64 | Any]: ...
86 @overload
87 def __call__(self, /, arg: _ArrayLikeComplex_co) -> npt.NDArray[np.complex128 | Any]: ...
88 @overload
89 def __call__(self, /, arg: _ArrayLikeCoefObject_co) -> npt.NDArray[np.object_]: ...
90
91 # unary ops
92 def __neg__(self, /) -> Self: ...
93 def __pos__(self, /) -> Self: ...
94
95 # binary ops
96 def __add__(self, x: _AnyOther, /) -> Self: ...
97 def __sub__(self, x: _AnyOther, /) -> Self: ...
98 def __mul__(self, x: _AnyOther, /) -> Self: ...
99 def __pow__(self, x: _AnyOther, /) -> Self: ...
100 def __truediv__(self, x: _AnyOther, /) -> Self: ...
101 def __floordiv__(self, x: _AnyOther, /) -> Self: ...
102 def __mod__(self, x: _AnyOther, /) -> Self: ...
103 def __divmod__(self, x: _AnyOther, /) -> _Tuple2[Self]: ...
104
105 # reflected binary ops
106 def __radd__(self, x: _AnyOther, /) -> Self: ...
107 def __rsub__(self, x: _AnyOther, /) -> Self: ...
108 def __rmul__(self, x: _AnyOther, /) -> Self: ...
109 def __rtruediv__(self, x: _AnyOther, /) -> Self: ...
110 def __rfloordiv__(self, x: _AnyOther, /) -> Self: ...
111 def __rmod__(self, x: _AnyOther, /) -> Self: ...
112 def __rdivmod__(self, x: _AnyOther, /) -> _Tuple2[Self]: ...
113
114 # iterable and sized
115 def __len__(self, /) -> int: ...
116 def __iter__(self, /) -> Iterator[np.float64 | Any]: ...
117
118 # pickling
119 def __getstate__(self, /) -> dict[str, Any]: ...
120 def __setstate__(self, dict: dict[str, Any], /) -> None: ...
121
122 #
123 def has_samecoef(self, /, other: ABCPolyBase) -> bool: ...
124 def has_samedomain(self, /, other: ABCPolyBase) -> bool: ...
125 def has_samewindow(self, /, other: ABCPolyBase) -> bool: ...
126 def has_sametype(self, /, other: object) -> TypeIs[Self]: ...
127
128 #
129 def copy(self, /) -> Self: ...
130 def degree(self, /) -> int: ...
131 def cutdeg(self, /, deg: int) -> Self: ...
132 def trim(self, /, tol: _FloatLike_co = 0) -> Self: ...
133 def truncate(self, /, size: _AnyInt) -> Self: ...
134
135 #
136 @overload
137 def convert(
138 self,
139 /,
140 domain: _SeriesLikeCoef_co | None,
141 kind: type[_PolyT],
142 window: _SeriesLikeCoef_co | None = None,
143 ) -> _PolyT: ...
144 @overload
145 def convert(
146 self,
147 /,
148 domain: _SeriesLikeCoef_co | None = None,
149 *,
150 kind: type[_PolyT],
151 window: _SeriesLikeCoef_co | None = None,
152 ) -> _PolyT: ...
153 @overload
154 def convert(
155 self,
156 /,
157 domain: _SeriesLikeCoef_co | None = None,
158 kind: None = None,
159 window: _SeriesLikeCoef_co | None = None,
160 ) -> Self: ...
161
162 #
163 def mapparms(self, /) -> _Tuple2[Any]: ...
164 def integ(
165 self,
166 /,
167 m: SupportsIndex = 1,
168 k: _CoefLike_co | _SeriesLikeCoef_co = [],
169 lbnd: _CoefLike_co | None = None,
170 ) -> Self: ...
171 def deriv(self, /, m: SupportsIndex = 1) -> Self: ...
172 def roots(self, /) -> _CoefSeries: ...
173 def linspace(
174 self,
175 /,
176 n: SupportsIndex = 100,
177 domain: _SeriesLikeCoef_co | None = None,
178 ) -> _Tuple2[_Series[np.float64 | np.complex128]]: ...
179
180 #
181 @overload
182 @classmethod
183 def fit(
184 cls,
185 x: _SeriesLikeCoef_co,
186 y: _SeriesLikeCoef_co,
187 deg: int | _SeriesLikeInt_co,
188 domain: _SeriesLikeCoef_co | None = None,
189 rcond: _FloatLike_co | None = None,
190 full: Literal[False] = False,
191 w: _SeriesLikeCoef_co | None = None,
192 window: _SeriesLikeCoef_co | None = None,
193 symbol: str = "x",
194 ) -> Self: ...
195 @overload
196 @classmethod
197 def fit(
198 cls,
199 x: _SeriesLikeCoef_co,
200 y: _SeriesLikeCoef_co,
201 deg: int | _SeriesLikeInt_co,
202 domain: _SeriesLikeCoef_co | None = None,
203 rcond: _FloatLike_co | None = None,
204 *,
205 full: Literal[True],
206 w: _SeriesLikeCoef_co | None = None,
207 window: _SeriesLikeCoef_co | None = None,
208 symbol: str = "x",
209 ) -> tuple[Self, Sequence[np.inexact | np.int32]]: ...
210 @overload
211 @classmethod
212 def fit(
213 cls,
214 x: _SeriesLikeCoef_co,
215 y: _SeriesLikeCoef_co,
216 deg: int | _SeriesLikeInt_co,
217 domain: _SeriesLikeCoef_co | None,
218 rcond: _FloatLike_co,
219 full: Literal[True],
220 /,
221 w: _SeriesLikeCoef_co | None = None,
222 window: _SeriesLikeCoef_co | None = None,
223 symbol: str = "x",
224 ) -> tuple[Self, Sequence[np.inexact | np.int32]]: ...
225
226 #
227 @classmethod
228 def fromroots(
229 cls,
230 roots: _ArrayLikeCoef_co,
231 domain: _SeriesLikeCoef_co | None = [],
232 window: _SeriesLikeCoef_co | None = None,
233 symbol: str = "x",
234 ) -> Self: ...
235 @classmethod
236 def identity(
237 cls,
238 domain: _SeriesLikeCoef_co | None = None,
239 window: _SeriesLikeCoef_co | None = None,
240 symbol: str = "x",
241 ) -> Self: ...
242 @classmethod
243 def basis(
244 cls,
245 deg: _AnyInt,
246 domain: _SeriesLikeCoef_co | None = None,
247 window: _SeriesLikeCoef_co | None = None,
248 symbol: str = "x",
249 ) -> Self: ...
250 @classmethod
251 def cast(
252 cls,
253 series: ABCPolyBase,
254 domain: _SeriesLikeCoef_co | None = None,
255 window: _SeriesLikeCoef_co | None = None,
256 ) -> Self: ...
257 @classmethod
258 def _str_term_unicode(cls, /, i: str, arg_str: str) -> str: ...
259 @classmethod
260 def _str_term_ascii(cls, /, i: str, arg_str: str) -> str: ...
261 @classmethod
262 def _repr_latex_term(cls, /, i: str, arg_str: str, needs_parens: bool) -> str: ...
263 