|
1 |
| -from typing import Any, Final, Literal as L, SupportsIndex as CanIndex, overload |
| 1 | +from collections.abc import Sequence |
| 2 | +from typing import Any, Final, Literal as L, Protocol, SupportsIndex, TypeAlias, overload, type_check_only |
| 3 | +from typing_extensions import Self, TypeVar |
2 | 4 |
|
3 | 5 | import numpy as np
|
4 | 6 | from _numtype import (
|
@@ -43,10 +45,11 @@ from _numtype import (
|
43 | 45 | ToObject_1nd,
|
44 | 46 | ToObject_nd,
|
45 | 47 | ToReal_1d,
|
| 48 | + _ToArray_1d, |
| 49 | + _ToArray_nd, |
46 | 50 | )
|
47 | 51 |
|
48 | 52 | from ._polybase import ABCPolyBase
|
49 |
| -from ._polytypes import _ArrayAndFitResult, _Indices, _ToNumeric_0d, _ToNumeric_1d, _ToNumeric_nd |
50 | 53 | from .polyutils import trimcoef as polytrim
|
51 | 54 |
|
52 | 55 | __all__ = [
|
@@ -82,6 +85,32 @@ __all__ = [
|
82 | 85 |
|
83 | 86 | ###
|
84 | 87 |
|
| 88 | +_ScalarT = TypeVar("_ScalarT", bound=np.generic) |
| 89 | + |
| 90 | +_Indices: TypeAlias = Sequence[SupportsIndex] |
| 91 | +_ArrayAndFitResult: TypeAlias = tuple[Array[_ScalarT], Sequence[np.inexact | np.int32]] |
| 92 | + |
| 93 | +_ToNumeric_0d: TypeAlias = ToComplex_0d | ToObject_0d | _SupportsCoefOps |
| 94 | +_ToNumeric_1d: TypeAlias = _ToArray_1d[np.number | np.bool | np.object_, complex | _SupportsCoefOps] |
| 95 | +_ToNumeric_nd: TypeAlias = _ToArray_nd[np.number | np.bool | np.object_, complex | _SupportsCoefOps] |
| 96 | + |
| 97 | +# compatible with e.g. int, float, complex, Decimal, Fraction, and ABCPolyBase |
| 98 | +@type_check_only |
| 99 | +class _SupportsCoefOps(Protocol): |
| 100 | + def __eq__(self, x: object, /) -> bool: ... |
| 101 | + def __ne__(self, x: object, /) -> bool: ... |
| 102 | + def __neg__(self, /) -> Self: ... |
| 103 | + def __pos__(self, /) -> Self: ... |
| 104 | + def __add__(self, x: Any, /) -> Self: ... |
| 105 | + def __sub__(self, x: Any, /) -> Self: ... |
| 106 | + def __mul__(self, x: Any, /) -> Self: ... |
| 107 | + def __pow__(self, x: Any, /) -> Self | float: ... |
| 108 | + def __radd__(self, x: Any, /) -> Self: ... |
| 109 | + def __rsub__(self, x: Any, /) -> Self: ... |
| 110 | + def __rmul__(self, x: Any, /) -> Self: ... |
| 111 | + |
| 112 | +### |
| 113 | + |
85 | 114 | polydomain: Final[Array_1d[np.float64]] = ...
|
86 | 115 | polyzero: Final[Array_1d[np.intp]] = ...
|
87 | 116 | polyone: Final[Array_1d[np.intp]] = ...
|
@@ -264,73 +293,83 @@ def polypow(c: ToObject_1d, pow: CoInteger_0d, maxpower: CoInteger_0d | None = N
|
264 | 293 |
|
265 | 294 | #
|
266 | 295 | @overload
|
267 |
| -def polyder(c: ToFloat64_nd | CoInteger_nd, m: CanIndex = 1, scl: CoFloating_0d = 1, axis: CanIndex = 0) -> Array[np.float64]: ... |
| 296 | +def polyder( |
| 297 | + c: ToFloat64_nd | CoInteger_nd, |
| 298 | + m: SupportsIndex = 1, |
| 299 | + scl: CoFloating_0d = 1, |
| 300 | + axis: SupportsIndex = 0, |
| 301 | +) -> Array[np.float64]: ... |
268 | 302 | @overload
|
269 |
| -def polyder(c: ToFloating_nd, m: CanIndex = 1, scl: CoFloating_0d = 1, axis: CanIndex = 0) -> Array[np.floating]: ... |
| 303 | +def polyder(c: ToFloating_nd, m: SupportsIndex = 1, scl: CoFloating_0d = 1, axis: SupportsIndex = 0) -> Array[np.floating]: ... |
270 | 304 | @overload
|
271 |
| -def polyder(c: ToComplex128_nd, m: CanIndex = 1, scl: CoComplex_0d = 1, axis: CanIndex = 0) -> Array[np.complex128]: ... |
| 305 | +def polyder(c: ToComplex128_nd, m: SupportsIndex = 1, scl: CoComplex_0d = 1, axis: SupportsIndex = 0) -> Array[np.complex128]: ... |
272 | 306 | @overload
|
273 |
| -def polyder(c: ToComplex_nd, m: CanIndex = 1, scl: CoComplex_0d = 1, axis: CanIndex = 0) -> Array[np.complexfloating]: ... |
| 307 | +def polyder( |
| 308 | + c: ToComplex_nd, |
| 309 | + m: SupportsIndex = 1, |
| 310 | + scl: CoComplex_0d = 1, |
| 311 | + axis: SupportsIndex = 0, |
| 312 | +) -> Array[np.complexfloating]: ... |
274 | 313 | @overload
|
275 |
| -def polyder(c: CoComplex_nd, m: CanIndex = 1, scl: CoComplex_0d = 1, axis: CanIndex = 0) -> Array[np.inexact]: ... |
| 314 | +def polyder(c: CoComplex_nd, m: SupportsIndex = 1, scl: CoComplex_0d = 1, axis: SupportsIndex = 0) -> Array[np.inexact]: ... |
276 | 315 | @overload
|
277 |
| -def polyder(c: ToObject_nd, m: CanIndex = 1, scl: _ToNumeric_0d = 1, axis: CanIndex = 0) -> Array[np.object_]: ... |
| 316 | +def polyder(c: ToObject_nd, m: SupportsIndex = 1, scl: _ToNumeric_0d = 1, axis: SupportsIndex = 0) -> Array[np.object_]: ... |
278 | 317 |
|
279 | 318 | #
|
280 | 319 | @overload
|
281 | 320 | def polyint(
|
282 | 321 | c: ToFloat64_nd | CoInteger_nd,
|
283 |
| - m: CanIndex = 1, |
| 322 | + m: SupportsIndex = 1, |
284 | 323 | k: CoFloat64_0d | CoFloat64_1d = [],
|
285 | 324 | lbnd: CoFloating_0d = 0,
|
286 | 325 | scl: CoFloating_0d = 1,
|
287 |
| - axis: CanIndex = 0, |
| 326 | + axis: SupportsIndex = 0, |
288 | 327 | ) -> Array[np.float64]: ...
|
289 | 328 | @overload
|
290 | 329 | def polyint(
|
291 | 330 | c: CoFloating_nd,
|
292 |
| - m: CanIndex = 1, |
| 331 | + m: SupportsIndex = 1, |
293 | 332 | k: CoFloating_0d | CoFloating_1d = [],
|
294 | 333 | lbnd: CoFloating_0d = 0,
|
295 | 334 | scl: CoFloating_0d = 1,
|
296 |
| - axis: CanIndex = 0, |
| 335 | + axis: SupportsIndex = 0, |
297 | 336 | ) -> Array[np.floating]: ...
|
298 | 337 | @overload
|
299 | 338 | def polyint(
|
300 | 339 | c: ToComplex_nd,
|
301 |
| - m: CanIndex = 1, |
| 340 | + m: SupportsIndex = 1, |
302 | 341 | k: CoComplex_0d | CoComplex_1d = [],
|
303 | 342 | lbnd: CoComplex_0d = 0,
|
304 | 343 | scl: CoComplex_0d = 1,
|
305 |
| - axis: CanIndex = 0, |
| 344 | + axis: SupportsIndex = 0, |
306 | 345 | ) -> Array[np.complexfloating]: ...
|
307 | 346 | @overload
|
308 | 347 | def polyint(
|
309 | 348 | c: CoComplex_nd,
|
310 |
| - m: CanIndex, |
| 349 | + m: SupportsIndex, |
311 | 350 | k: ToComplex_0d | ToComplex_1d,
|
312 | 351 | lbnd: CoComplex_0d = 0,
|
313 | 352 | scl: CoComplex_0d = 1,
|
314 |
| - axis: CanIndex = 0, |
| 353 | + axis: SupportsIndex = 0, |
315 | 354 | ) -> Array[np.complexfloating]: ...
|
316 | 355 | @overload
|
317 | 356 | def polyint(
|
318 | 357 | c: CoComplex_nd,
|
319 |
| - m: CanIndex = 1, |
| 358 | + m: SupportsIndex = 1, |
320 | 359 | *,
|
321 | 360 | k: ToComplex_0d | ToComplex_1d,
|
322 | 361 | lbnd: CoComplex_0d = 0,
|
323 | 362 | scl: CoComplex_0d = 1,
|
324 |
| - axis: CanIndex = 0, |
| 363 | + axis: SupportsIndex = 0, |
325 | 364 | ) -> Array[np.complexfloating]: ...
|
326 | 365 | @overload
|
327 | 366 | def polyint(
|
328 | 367 | c: ToObject_nd,
|
329 |
| - m: CanIndex = 1, |
| 368 | + m: SupportsIndex = 1, |
330 | 369 | k: _ToNumeric_0d | _ToNumeric_1d = [],
|
331 | 370 | lbnd: _ToNumeric_0d = 0,
|
332 | 371 | scl: _ToNumeric_0d = 1,
|
333 |
| - axis: CanIndex = 0, |
| 372 | + axis: SupportsIndex = 0, |
334 | 373 | ) -> Array[np.object_]: ...
|
335 | 374 |
|
336 | 375 | #
|
@@ -563,19 +602,19 @@ def polygrid3d(x: _ToNumeric_nd, y: _ToNumeric_nd, z: _ToNumeric_nd, c: ToObject
|
563 | 602 |
|
564 | 603 | #
|
565 | 604 | @overload
|
566 |
| -def polyvander(x: ToFloat64_nd | CoInteger_nd, deg: CanIndex) -> Array[np.float64]: ... |
| 605 | +def polyvander(x: ToFloat64_nd | CoInteger_nd, deg: SupportsIndex) -> Array[np.float64]: ... |
567 | 606 | @overload
|
568 |
| -def polyvander(x: CoFloating_nd, deg: CanIndex) -> Array[np.floating]: ... |
| 607 | +def polyvander(x: CoFloating_nd, deg: SupportsIndex) -> Array[np.floating]: ... |
569 | 608 | @overload
|
570 |
| -def polyvander(x: ToComplex128_nd, deg: CanIndex) -> Array[np.complex128]: ... |
| 609 | +def polyvander(x: ToComplex128_nd, deg: SupportsIndex) -> Array[np.complex128]: ... |
571 | 610 | @overload
|
572 |
| -def polyvander(x: ToComplex_nd, deg: CanIndex) -> Array[np.complexfloating]: ... |
| 611 | +def polyvander(x: ToComplex_nd, deg: SupportsIndex) -> Array[np.complexfloating]: ... |
573 | 612 | @overload
|
574 |
| -def polyvander(x: CoComplex_nd, deg: CanIndex) -> Array[np.inexact]: ... |
| 613 | +def polyvander(x: CoComplex_nd, deg: SupportsIndex) -> Array[np.inexact]: ... |
575 | 614 | @overload
|
576 |
| -def polyvander(x: ToObject_nd, deg: CanIndex) -> Array[np.object_]: ... |
| 615 | +def polyvander(x: ToObject_nd, deg: SupportsIndex) -> Array[np.object_]: ... |
577 | 616 | @overload
|
578 |
| -def polyvander(x: _ToNumeric_nd, deg: CanIndex) -> Array[Any]: ... |
| 617 | +def polyvander(x: _ToNumeric_nd, deg: SupportsIndex) -> Array[Any]: ... |
579 | 618 |
|
580 | 619 | #
|
581 | 620 | @overload
|
|
0 commit comments