Skip to content

Commit 8f48bfd

Browse files
committed
🎨 refactor from _numtype import in polynomial
1 parent 2f849d4 commit 8f48bfd

8 files changed

Lines changed: 574 additions & 595 deletions

File tree

‎src/numpy-stubs/polynomial/_polybase.pyi‎

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,9 @@ from collections.abc import Iterator, Mapping, Sequence
44
from typing import Any, ClassVar, Final, Literal, SupportsIndex, TypeAlias, overload
55
from typing_extensions import Self, TypeIs, TypeVar, override
66

7+
import _numtype as _nt
78
import numpy as np
89
import numpy.typing as npt
9-
from _numtype import (
10-
Array1D,
11-
CoComplex_0d,
12-
CoComplex_1d,
13-
CoComplex_1nd,
14-
CoInteger_0d,
15-
CoInteger_1d,
16-
ToObject_0d,
17-
ToObject_1nd,
18-
)
1910
from numpy._typing import _FloatLike_co
2011

2112
from .polynomial import _ToNumeric_0d, _ToNumeric_nd
@@ -24,9 +15,11 @@ __all__: Final[Sequence[str]] = ("ABCPolyBase",)
2415

2516
###
2617

18+
_T = TypeVar("_T")
2719
_PolyT = TypeVar("_PolyT", bound=ABCPolyBase)
2820

29-
_AnyOther: TypeAlias = ABCPolyBase | _ToNumeric_0d | CoComplex_1d
21+
_Tuple2: TypeAlias = tuple[_T, _T]
22+
_AnyOther: TypeAlias = ABCPolyBase | _ToNumeric_0d | _nt.CoComplex_1d
3023
_Hundred: TypeAlias = Literal[100]
3124

3225
###
@@ -41,7 +34,7 @@ class ABCPolyBase(abc.ABC):
4134
_use_unicode: ClassVar[bool]
4235
_symbol: str
4336

44-
coef: Array1D[np.inexact | np.object_]
37+
coef: _nt.Array1D[np.inexact | np.object_]
4538

4639
@property
4740
def symbol(self, /) -> str: ...
@@ -52,32 +45,32 @@ class ABCPolyBase(abc.ABC):
5245
def basis_name(self, /) -> str | None: ...
5346
@property
5447
@abc.abstractmethod
55-
def domain(self, /) -> Array1D[np.inexact]: ...
48+
def domain(self, /) -> _nt.Array1D[np.inexact]: ...
5649
@property
5750
@abc.abstractmethod
58-
def window(self, /) -> Array1D[np.inexact]: ...
51+
def window(self, /) -> _nt.Array1D[np.inexact]: ...
5952

6053
#
6154
def __init__(
6255
self,
6356
/,
64-
coef: CoComplex_1d,
65-
domain: CoComplex_1d | None = None,
66-
window: CoComplex_1d | None = None,
57+
coef: _nt.CoComplex_1d,
58+
domain: _nt.CoComplex_1d | None = None,
59+
window: _nt.CoComplex_1d | None = None,
6760
symbol: str = "x",
6861
) -> None: ...
6962

7063
#
7164
@overload
7265
def __call__(self, /, arg: _PolyT) -> _PolyT: ...
7366
@overload
74-
def __call__(self, /, arg: CoComplex_0d) -> np.float64 | np.complex128: ...
67+
def __call__(self, /, arg: _nt.CoComplex_0d) -> _nt.inexact64: ...
7568
@overload
76-
def __call__(self, /, arg: CoComplex_1nd) -> npt.NDArray[np.float64 | np.complex128]: ...
69+
def __call__(self, /, arg: _nt.CoComplex_1nd) -> npt.NDArray[_nt.inexact64]: ...
7770
@overload
78-
def __call__(self, /, arg: ToObject_0d) -> Any: ...
71+
def __call__(self, /, arg: _nt.ToObject_0d) -> Any: ...
7972
@overload
80-
def __call__(self, /, arg: ToObject_1nd) -> npt.NDArray[np.object_]: ...
73+
def __call__(self, /, arg: _nt.ToObject_1nd) -> npt.NDArray[np.object_]: ...
8174

8275
#
8376
@override
@@ -132,78 +125,90 @@ class ABCPolyBase(abc.ABC):
132125
#
133126
@overload
134127
def convert(
135-
self, /, domain: CoComplex_1d | None = None, kind: None = None, window: CoComplex_1d | None = None
128+
self,
129+
/,
130+
domain: _nt.CoComplex_1d | None = None,
131+
kind: None = None,
132+
window: _nt.CoComplex_1d | None = None,
136133
) -> Self: ...
137134
@overload
138135
def convert(
139-
self, /, domain: CoComplex_1d | None, kind: type[_PolyT], window: CoComplex_1d | None = None
136+
self,
137+
/,
138+
domain: _nt.CoComplex_1d | None,
139+
kind: type[_PolyT],
140+
window: _nt.CoComplex_1d | None = None,
140141
) -> _PolyT: ...
141142
@overload
142143
def convert(
143144
self,
144145
/,
145-
domain: CoComplex_1d | None = None,
146+
domain: _nt.CoComplex_1d | None = None,
146147
*,
147148
kind: type[_PolyT],
148-
window: CoComplex_1d | None = None,
149+
window: _nt.CoComplex_1d | None = None,
149150
) -> _PolyT: ...
150151

151152
#
152153
def mapparms(self, /) -> tuple[Any, Any]: ...
153154
def integ(
154-
self, /, m: SupportsIndex = 1, k: _ToNumeric_0d | CoComplex_1d = [], lbnd: _ToNumeric_0d | None = None
155+
self,
156+
/,
157+
m: SupportsIndex = 1,
158+
k: _ToNumeric_0d | _nt.CoComplex_1d = [],
159+
lbnd: _ToNumeric_0d | None = None,
155160
) -> Self: ...
156161
def deriv(self, /, m: SupportsIndex = 1) -> Self: ...
157-
def roots(self, /) -> Array1D[np.float64] | Array1D[np.complex128]: ...
162+
def roots(self, /) -> _nt.Array1D[_nt.inexact64]: ...
158163
def linspace(
159164
self,
160165
/,
161166
n: SupportsIndex = 100,
162-
domain: CoComplex_1d | None = None,
163-
) -> tuple[Array1D[np.float64 | np.complex128], Array1D[np.float64 | np.complex128]]: ...
167+
domain: _nt.CoComplex_1d | None = None,
168+
) -> _Tuple2[_nt.Array1D[_nt.inexact64]]: ...
164169

165170
#
166171
@overload
167172
@classmethod
168173
def fit(
169174
cls,
170-
x: CoComplex_1d,
171-
y: CoComplex_1d,
172-
deg: CoInteger_0d | CoInteger_1d,
173-
domain: CoComplex_1d | None = None,
175+
x: _nt.CoComplex_1d,
176+
y: _nt.CoComplex_1d,
177+
deg: _nt.CoInteger_0d | _nt.CoInteger_1d,
178+
domain: _nt.CoComplex_1d | None = None,
174179
rcond: _FloatLike_co | None = None,
175180
full: Literal[False] = False,
176-
w: CoComplex_1d | None = None,
177-
window: CoComplex_1d | None = None,
181+
w: _nt.CoComplex_1d | None = None,
182+
window: _nt.CoComplex_1d | None = None,
178183
symbol: str = "x",
179184
) -> Self: ...
180185
@overload
181186
@classmethod
182187
def fit(
183188
cls,
184-
x: CoComplex_1d,
185-
y: CoComplex_1d,
186-
deg: CoInteger_0d | CoInteger_1d,
187-
domain: CoComplex_1d | None,
189+
x: _nt.CoComplex_1d,
190+
y: _nt.CoComplex_1d,
191+
deg: _nt.CoInteger_0d | _nt.CoInteger_1d,
192+
domain: _nt.CoComplex_1d | None,
188193
rcond: _FloatLike_co | None,
189194
full: Literal[True],
190-
w: CoComplex_1d | None = None,
191-
window: CoComplex_1d | None = None,
195+
w: _nt.CoComplex_1d | None = None,
196+
window: _nt.CoComplex_1d | None = None,
192197
symbol: str = "x",
193198
) -> tuple[Self, Sequence[np.inexact | np.int32]]: ...
194199
@overload
195200
@classmethod
196201
def fit(
197202
cls,
198-
x: CoComplex_1d,
199-
y: CoComplex_1d,
200-
deg: CoInteger_0d | CoInteger_1d,
201-
domain: CoComplex_1d | None = None,
203+
x: _nt.CoComplex_1d,
204+
y: _nt.CoComplex_1d,
205+
deg: _nt.CoInteger_0d | _nt.CoInteger_1d,
206+
domain: _nt.CoComplex_1d | None = None,
202207
rcond: _FloatLike_co | None = None,
203208
*,
204209
full: Literal[True],
205-
w: CoComplex_1d | None = None,
206-
window: CoComplex_1d | None = None,
210+
w: _nt.CoComplex_1d | None = None,
211+
window: _nt.CoComplex_1d | None = None,
207212
symbol: str = "x",
208213
) -> tuple[Self, Sequence[np.inexact | np.int32]]: ...
209214

@@ -212,31 +217,31 @@ class ABCPolyBase(abc.ABC):
212217
def fromroots(
213218
cls,
214219
roots: _ToNumeric_nd,
215-
domain: CoComplex_1d | None = [],
216-
window: CoComplex_1d | None = None,
220+
domain: _nt.CoComplex_1d | None = [],
221+
window: _nt.CoComplex_1d | None = None,
217222
symbol: str = "x",
218223
) -> Self: ...
219224
@classmethod
220225
def identity(
221226
cls,
222-
domain: CoComplex_1d | None = None,
223-
window: CoComplex_1d | None = None,
227+
domain: _nt.CoComplex_1d | None = None,
228+
window: _nt.CoComplex_1d | None = None,
224229
symbol: str = "x",
225230
) -> Self: ...
226231
@classmethod
227232
def basis(
228233
cls,
229234
deg: SupportsIndex,
230-
domain: CoComplex_1d | None = None,
231-
window: CoComplex_1d | None = None,
235+
domain: _nt.CoComplex_1d | None = None,
236+
window: _nt.CoComplex_1d | None = None,
232237
symbol: str = "x",
233238
) -> Self: ...
234239
@classmethod
235240
def cast(
236241
cls,
237242
series: ABCPolyBase,
238-
domain: CoComplex_1d | None = None,
239-
window: CoComplex_1d | None = None,
243+
domain: _nt.CoComplex_1d | None = None,
244+
window: _nt.CoComplex_1d | None = None,
240245
) -> Self: ...
241246

242247
#

‎src/numpy-stubs/polynomial/chebyshev.pyi‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ from collections.abc import Callable, Iterable
22
from typing import Concatenate, Final, Literal as L, SupportsIndex as CanIndex, TypeAlias, overload
33
from typing_extensions import Self, TypeVar
44

5+
import _numtype as _nt
56
import numpy as np
6-
from _numtype import Array, Array1D, CoComplex_1d, CoInteger_0d, _ToArray_1d
77

88
from ._polybase import ABCPolyBase
99
from .legendre import (
@@ -75,51 +75,52 @@ __all__ = [
7575
###
7676

7777
_T = TypeVar("_T")
78-
_NumT = TypeVar("_NumT", bound=np.number | np.object_)
78+
_NumericT = TypeVar("_NumericT", bound=np.number | np.object_)
7979

80-
_Func: TypeAlias = Callable[Concatenate[Array1D[np.float64], ...], _T]
80+
_Args: TypeAlias = Iterable[object]
81+
_Func: TypeAlias = Callable[Concatenate[_nt.Array1D[np.float64], ...], _T]
8182

8283
###
8384

84-
chebdomain: Final[Array1D[np.float64]] = ...
85-
chebzero: Final[Array1D[np.intp]] = ...
86-
chebone: Final[Array1D[np.intp]] = ...
87-
chebx: Final[Array1D[np.intp]] = ...
85+
chebdomain: Final[_nt.Array1D[np.float64]] = ...
86+
chebzero: Final[_nt.Array1D[np.intp]] = ...
87+
chebone: Final[_nt.Array1D[np.intp]] = ...
88+
chebx: Final[_nt.Array1D[np.intp]] = ...
8889

8990
class Chebyshev(ABCPolyBase):
90-
domain: Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
91-
window: Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
91+
domain: _nt.Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
92+
window: _nt.Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
9293
basis_name: L["T"] = "T" # pyright: ignore[reportIncompatibleMethodOverride]
9394

9495
@classmethod
9596
def interpolate(
9697
cls,
97-
func: np.ufunc | _Func[CoComplex_1d],
98-
deg: CoInteger_0d,
99-
domain: CoComplex_1d | None = None,
100-
args: tuple[object, ...] = (),
98+
func: np.ufunc | _Func[_nt.CoComplex_1d],
99+
deg: _nt.CoInteger_0d,
100+
domain: _nt.CoComplex_1d | None = None,
101+
args: _Args = (),
101102
) -> Self: ...
102103

103104
#
104105
@overload
105-
def chebinterpolate(func: np.ufunc, deg: CoInteger_0d, args: Iterable[object] = ()) -> Array[np.float64]: ...
106+
def chebinterpolate(func: np.ufunc, deg: _nt.CoInteger_0d, args: _Args = ()) -> _nt.Array[np.float64]: ...
106107
@overload
107108
def chebinterpolate(
108-
func: _Func[_ToArray_1d[_NumT]], deg: CoInteger_0d, args: tuple[object, ...] = ()
109-
) -> Array1D[_NumT]: ...
109+
func: _Func[_nt._ToArray_1d[_NumericT]], deg: _nt.CoInteger_0d, args: _Args = ()
110+
) -> _nt.Array1D[_NumericT]: ...
110111

111112
#
112-
def chebpts1(npts: CanIndex) -> Array1D[np.float64]: ...
113-
def chebpts2(npts: CanIndex) -> Array1D[np.float64]: ...
113+
def chebpts1(npts: CanIndex) -> _nt.Array1D[np.float64]: ...
114+
def chebpts2(npts: CanIndex) -> _nt.Array1D[np.float64]: ...
114115

115116
#
116-
def _cseries_to_zseries(c: Array[_NumT]) -> Array1D[_NumT]: ...
117-
def _zseries_to_cseries(zs: Array[_NumT]) -> Array1D[_NumT]: ...
117+
def _cseries_to_zseries(c: _nt.Array[_NumericT]) -> _nt.Array1D[_NumericT]: ...
118+
def _zseries_to_cseries(zs: _nt.Array[_NumericT]) -> _nt.Array1D[_NumericT]: ...
118119

119120
#
120-
def _zseries_mul(z1: Array[_NumT], z2: Array[_NumT]) -> Array1D[_NumT]: ...
121-
def _zseries_div(z1: Array[_NumT], z2: Array[_NumT]) -> Array1D[_NumT]: ...
121+
def _zseries_mul(z1: _nt.Array[_NumericT], z2: _nt.Array[_NumericT]) -> _nt.Array1D[_NumericT]: ...
122+
def _zseries_div(z1: _nt.Array[_NumericT], z2: _nt.Array[_NumericT]) -> _nt.Array1D[_NumericT]: ...
122123

123124
#
124-
def _zseries_der(zs: Array[_NumT]) -> Array1D[_NumT]: ...
125-
def _zseries_int(zs: Array[_NumT]) -> Array1D[_NumT]: ...
125+
def _zseries_der(zs: _nt.Array[_NumericT]) -> _nt.Array1D[_NumericT]: ...
126+
def _zseries_int(zs: _nt.Array[_NumericT]) -> _nt.Array1D[_NumericT]: ...

‎src/numpy-stubs/polynomial/hermite.pyi‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Final, Literal as L
22
from typing_extensions import TypeVar
33

4+
import _numtype as _nt
45
import numpy as np
5-
from _numtype import Array, Array1D
66

77
from ._polybase import ABCPolyBase
88
from .legendre import (
@@ -74,14 +74,14 @@ _ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
7474

7575
###
7676

77-
hermdomain: Final[Array1D[np.float64]] = ...
78-
hermzero: Final[Array1D[np.int_]] = ...
79-
hermone: Final[Array1D[np.int_]] = ...
80-
hermx: Final[Array1D[np.int_]] = ...
77+
hermdomain: Final[_nt.Array1D[np.float64]] = ...
78+
hermzero: Final[_nt.Array1D[np.intp]] = ...
79+
hermone: Final[_nt.Array1D[np.intp]] = ...
80+
hermx: Final[_nt.Array1D[np.intp]] = ...
8181

8282
class Hermite(ABCPolyBase):
83-
domain: Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
84-
window: Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
83+
domain: _nt.Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
84+
window: _nt.Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
8585
basis_name: L["H"] = "H" # pyright: ignore[reportIncompatibleMethodOverride]
8686

87-
def _normed_hermite_n(x: Array[np.float64, _ShapeT], n: int | np.intp) -> Array[np.float64, _ShapeT]: ...
87+
def _normed_hermite_n(x: _nt.Array[np.float64, _ShapeT], n: int | np.intp) -> _nt.Array[np.float64, _ShapeT]: ...

‎src/numpy-stubs/polynomial/hermite_e.pyi‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Final, Literal as L
22
from typing_extensions import TypeVar
33

4+
import _numtype as _nt
45
import numpy as np
5-
from _numtype import Array, Array1D
66

77
from ._polybase import ABCPolyBase
88
from .legendre import (
@@ -74,14 +74,14 @@ _ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...])
7474

7575
###
7676

77-
hermedomain: Final[Array1D[np.float64]] = ...
78-
hermezero: Final[Array1D[np.int_]] = ...
79-
hermeone: Final[Array1D[np.int_]] = ...
80-
hermex: Final[Array1D[np.int_]] = ...
77+
hermedomain: Final[_nt.Array1D[np.float64]] = ...
78+
hermezero: Final[_nt.Array1D[np.int_]] = ...
79+
hermeone: Final[_nt.Array1D[np.int_]] = ...
80+
hermex: Final[_nt.Array1D[np.int_]] = ...
8181

8282
class HermiteE(ABCPolyBase):
83-
domain: Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
84-
window: Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
83+
domain: _nt.Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
84+
window: _nt.Array1D[np.float64] = ... # pyright: ignore[reportIncompatibleMethodOverride]
8585
basis_name: L["He"] = "He" # pyright: ignore[reportIncompatibleMethodOverride]
8686

87-
def _normed_hermite_e_n(x: Array[np.float64, _ShapeT], n: int | np.intp) -> Array[np.float64, _ShapeT]: ...
87+
def _normed_hermite_e_n(x: _nt.Array[np.float64, _ShapeT], n: int | np.intp) -> _nt.Array[np.float64, _ShapeT]: ...

0 commit comments

Comments
 (0)