codekingpro/portable-devtools
114k
1"""A module with private type-check-only `numpy.ufunc` subclasses.
2
3The signatures of the ufuncs are too varied to reasonably type
4with a single class. So instead, `ufunc` has been expanded into
5four private subclasses, one for each combination of
6`~ufunc.nin` and `~ufunc.nout`.
7""" # noqa: PYI021
8
9from _typeshed import Incomplete
10from types import EllipsisType
11from typing import (
12 Any,
13 Generic,
14 Literal,
15 LiteralString,
16 Never,
17 NoReturn,
18 Protocol,
19 SupportsIndex,
20 TypeAlias,
21 TypedDict,
22 TypeVar,
23 Unpack,
24 overload,
25 type_check_only,
26)
27
28import numpy as np
29from numpy import _CastingKind, _OrderKACF, ufunc
30from numpy.typing import NDArray
31
32from ._array_like import ArrayLike, _ArrayLikeBool_co, _ArrayLikeInt_co
33from ._dtype_like import DTypeLike
34from ._scalars import _ScalarLike_co
35from ._shape import _ShapeLike
36
37_T = TypeVar("_T")
38_2Tuple: TypeAlias = tuple[_T, _T]
39_3Tuple: TypeAlias = tuple[_T, _T, _T]
40_4Tuple: TypeAlias = tuple[_T, _T, _T, _T]
41
42_2PTuple: TypeAlias = tuple[_T, _T, *tuple[_T, ...]]
43_3PTuple: TypeAlias = tuple[_T, _T, _T, *tuple[_T, ...]]
44_4PTuple: TypeAlias = tuple[_T, _T, _T, _T, *tuple[_T, ...]]
45
46_NTypes = TypeVar("_NTypes", bound=int, covariant=True)
47_IDType = TypeVar("_IDType", covariant=True)
48_NameType = TypeVar("_NameType", bound=LiteralString, covariant=True)
49_Signature = TypeVar("_Signature", bound=LiteralString, covariant=True)
50
51_NIn = TypeVar("_NIn", bound=int, covariant=True)
52_NOut = TypeVar("_NOut", bound=int, covariant=True)
53_ReturnType_co = TypeVar("_ReturnType_co", covariant=True)
54_ArrayT = TypeVar("_ArrayT", bound=np.ndarray)
55
56@type_check_only
57class _SupportsArrayUFunc(Protocol):
58 def __array_ufunc__(
59 self,
60 ufunc: ufunc,
61 method: Literal["__call__", "reduce", "reduceat", "accumulate", "outer", "at"],
62 *inputs: Any,
63 **kwargs: Any,
64 ) -> Any: ...
65
66@type_check_only
67class _UFunc3Kwargs(TypedDict, total=False):
68 where: _ArrayLikeBool_co | None
69 casting: _CastingKind
70 order: _OrderKACF
71 subok: bool
72 signature: _3Tuple[str | None] | str | None
73
74@type_check_only
75class _ReduceKwargs(TypedDict, total=False):
76 initial: Incomplete # = <no value>
77 where: _ArrayLikeBool_co | None # = True
78
79# NOTE: `reduce`, `accumulate`, `reduceat` and `outer` raise a ValueError for
80# ufuncs that don't accept two input arguments and return one output argument.
81# In such cases the respective methods return `NoReturn`
82
83# NOTE: Similarly, `at` won't be defined for ufuncs that return
84# multiple outputs; in such cases `at` is typed to return `NoReturn`
85
86# NOTE: If 2 output types are returned then `out` must be a
87# 2-tuple of arrays. Otherwise `None` or a plain array are also acceptable
88
89# pyright: reportIncompatibleMethodOverride=false
90
91@type_check_only
92class _UFunc_Nin1_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
93 @property
94 def __name__(self) -> _NameType: ...
95 @property
96 def __qualname__(self) -> _NameType: ... # pyright: ignore[reportIncompatibleVariableOverride]
97 @property
98 def ntypes(self) -> _NTypes: ...
99 @property
100 def identity(self) -> _IDType: ...
101 @property
102 def nin(self) -> Literal[1]: ...
103 @property
104 def nout(self) -> Literal[1]: ...
105 @property
106 def nargs(self) -> Literal[2]: ...
107 @property
108 def signature(self) -> None: ...
109
110 @overload
111 def __call__(
112 self,
113 x1: _ScalarLike_co,
114 /,
115 out: None = None,
116 *,
117 dtype: DTypeLike | None = None,
118 where: _ArrayLikeBool_co | None = True,
119 casting: _CastingKind = ...,
120 order: _OrderKACF = ...,
121 subok: bool = ...,
122 signature: str | _2Tuple[str | None] = ...,
123 ) -> Incomplete: ...
124 @overload
125 def __call__(
126 self,
127 x1: ArrayLike,
128 /,
129 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
130 *,
131 dtype: DTypeLike | None = None,
132 where: _ArrayLikeBool_co | None = True,
133 casting: _CastingKind = ...,
134 order: _OrderKACF = ...,
135 subok: bool = ...,
136 signature: str | _2Tuple[str | None] = ...,
137 ) -> NDArray[Incomplete]: ...
138 @overload
139 def __call__(
140 self,
141 x1: _SupportsArrayUFunc,
142 /,
143 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
144 *,
145 dtype: DTypeLike | None = None,
146 where: _ArrayLikeBool_co | None = True,
147 casting: _CastingKind = ...,
148 order: _OrderKACF = ...,
149 subok: bool = ...,
150 signature: str | _2Tuple[str | None] = ...,
151 ) -> Incomplete: ...
152
153 def accumulate(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
154 def reduce(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
155 def reduceat(self, array: Never, /, indices: Never) -> NoReturn: ... # type: ignore[override]
156 def outer(self, A: Never, B: Never, /) -> NoReturn: ... # type: ignore[override]
157
158 def at(self, a: np.ndarray | _SupportsArrayUFunc, indices: _ArrayLikeInt_co, /) -> None: ... # type: ignore[override]
159
160@type_check_only
161class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
162 @property
163 def __name__(self) -> _NameType: ...
164 @property
165 def __qualname__(self) -> _NameType: ... # pyright: ignore[reportIncompatibleVariableOverride]
166 @property
167 def ntypes(self) -> _NTypes: ...
168 @property
169 def identity(self) -> _IDType: ...
170 @property
171 def nin(self) -> Literal[2]: ...
172 @property
173 def nout(self) -> Literal[1]: ...
174 @property
175 def nargs(self) -> Literal[3]: ...
176 @property
177 def signature(self) -> None: ...
178
179 @overload # (scalar, scalar) -> scalar
180 def __call__(
181 self,
182 x1: _ScalarLike_co,
183 x2: _ScalarLike_co,
184 /,
185 out: EllipsisType | None = None,
186 *,
187 dtype: DTypeLike | None = None,
188 **kwds: Unpack[_UFunc3Kwargs],
189 ) -> Incomplete: ...
190 @overload # (array-like, array) -> array
191 def __call__(
192 self,
193 x1: ArrayLike,
194 x2: np.ndarray,
195 /,
196 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
197 *,
198 dtype: DTypeLike | None = None,
199 **kwds: Unpack[_UFunc3Kwargs],
200 ) -> NDArray[Incomplete]: ...
201 @overload # (array, array-like) -> array
202 def __call__(
203 self,
204 x1: np.ndarray,
205 x2: ArrayLike,
206 /,
207 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
208 *,
209 dtype: DTypeLike | None = None,
210 **kwds: Unpack[_UFunc3Kwargs],
211 ) -> NDArray[Incomplete]: ...
212 @overload # (array-like, array-like, out=array) -> array
213 def __call__(
214 self,
215 x1: ArrayLike,
216 x2: ArrayLike,
217 /,
218 out: np.ndarray | tuple[np.ndarray],
219 *,
220 dtype: DTypeLike | None = None,
221 **kwds: Unpack[_UFunc3Kwargs],
222 ) -> NDArray[Incomplete]: ...
223 @overload # (array-like, array-like) -> array | scalar
224 def __call__(
225 self,
226 x1: ArrayLike,
227 x2: ArrayLike,
228 /,
229 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
230 *,
231 dtype: DTypeLike | None = None,
232 **kwds: Unpack[_UFunc3Kwargs],
233 ) -> NDArray[Incomplete] | Incomplete: ...
234
235 def accumulate(
236 self,
237 array: ArrayLike,
238 /,
239 axis: SupportsIndex = 0,
240 dtype: DTypeLike | None = None,
241 out: np.ndarray | EllipsisType | None = None,
242 ) -> NDArray[Incomplete]: ...
243
244 @overload # type: ignore[override]
245 def reduce( # out=None (default), keepdims=False (default)
246 self,
247 array: ArrayLike,
248 /,
249 axis: _ShapeLike | None = 0,
250 dtype: DTypeLike | None = None,
251 out: None = None,
252 *,
253 keepdims: Literal[False] = False,
254 **kwargs: Unpack[_ReduceKwargs],
255 ) -> Incomplete: ...
256 @overload # out=ndarray or out=...
257 def reduce(
258 self,
259 array: ArrayLike,
260 /,
261 axis: _ShapeLike | None = 0,
262 dtype: DTypeLike | None = None,
263 *,
264 out: np.ndarray | EllipsisType,
265 keepdims: bool = False,
266 **kwargs: Unpack[_ReduceKwargs],
267 ) -> NDArray[Incomplete]: ...
268 @overload # keepdims=True
269 def reduce(
270 self,
271 array: ArrayLike,
272 /,
273 axis: _ShapeLike | None = 0,
274 dtype: DTypeLike | None = None,
275 out: np.ndarray | EllipsisType | None = None,
276 *,
277 keepdims: Literal[True],
278 **kwargs: Unpack[_ReduceKwargs],
279 ) -> NDArray[Incomplete]: ...
280
281 def reduceat(
282 self,
283 array: ArrayLike,
284 /,
285 indices: _ArrayLikeInt_co,
286 axis: SupportsIndex = 0,
287 dtype: DTypeLike | None = None,
288 out: np.ndarray | EllipsisType | None = None,
289 ) -> NDArray[Incomplete]: ...
290
291 @overload # type: ignore[override]
292 def outer( # (scalar, scalar) -> scalar
293 self,
294 A: _ScalarLike_co,
295 B: _ScalarLike_co,
296 /,
297 *,
298 out: None = None,
299 dtype: DTypeLike | None = None,
300 **kwds: Unpack[_UFunc3Kwargs],
301 ) -> Incomplete: ...
302 @overload # (array-like, array) -> array
303 def outer(
304 self,
305 A: ArrayLike,
306 B: np.ndarray,
307 /,
308 *,
309 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
310 dtype: DTypeLike | None = None,
311 **kwds: Unpack[_UFunc3Kwargs],
312 ) -> NDArray[Incomplete]: ...
313 @overload # (array, array-like) -> array
314 def outer(
315 self,
316 A: np.ndarray,
317 B: ArrayLike,
318 /,
319 *,
320 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
321 dtype: DTypeLike | None = None,
322 **kwds: Unpack[_UFunc3Kwargs],
323 ) -> NDArray[Incomplete]: ...
324 @overload # (array-like, array-like, out=array) -> array
325 def outer(
326 self,
327 A: ArrayLike,
328 B: ArrayLike,
329 /,
330 *,
331 out: np.ndarray | tuple[np.ndarray] | EllipsisType,
332 dtype: DTypeLike | None = None,
333 **kwds: Unpack[_UFunc3Kwargs],
334 ) -> NDArray[Incomplete]: ...
335 @overload # (array-like, array-like) -> array | scalar
336 def outer(
337 self,
338 A: ArrayLike,
339 B: ArrayLike,
340 /,
341 *,
342 out: None = None,
343 dtype: DTypeLike | None = None,
344 **kwds: Unpack[_UFunc3Kwargs],
345 ) -> NDArray[Incomplete] | Incomplete: ...
346
347 def at( # type: ignore[override]
348 self,
349 a: np.ndarray | _SupportsArrayUFunc,
350 indices: _ArrayLikeInt_co,
351 b: ArrayLike,
352 /,
353 ) -> None: ...
354
355@type_check_only
356class _UFunc_Nin1_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
357 @property
358 def __name__(self) -> _NameType: ...
359 @property
360 def __qualname__(self) -> _NameType: ... # pyright: ignore[reportIncompatibleVariableOverride]
361 @property
362 def ntypes(self) -> _NTypes: ...
363 @property
364 def identity(self) -> _IDType: ...
365 @property
366 def nin(self) -> Literal[1]: ...
367 @property
368 def nout(self) -> Literal[2]: ...
369 @property
370 def nargs(self) -> Literal[3]: ...
371 @property
372 def signature(self) -> None: ...
373
374 @overload
375 def __call__(
376 self,
377 x1: _ScalarLike_co,
378 out1: EllipsisType | None = ...,
379 out2: None = None,
380 /,
381 *,
382 out: EllipsisType | None = ...,
383 dtype: DTypeLike | None = None,
384 where: _ArrayLikeBool_co | None = True,
385 casting: _CastingKind = ...,
386 order: _OrderKACF = ...,
387 subok: bool = ...,
388 signature: str | _3Tuple[str | None] = ...,
389 ) -> _2Tuple[Incomplete]: ...
390 @overload
391 def __call__(
392 self,
393 x1: ArrayLike,
394 out1: np.ndarray | EllipsisType | None = ...,
395 out2: np.ndarray | None = ...,
396 /,
397 *,
398 out: _2Tuple[np.ndarray] | EllipsisType = ...,
399 dtype: DTypeLike | None = None,
400 where: _ArrayLikeBool_co | None = True,
401 casting: _CastingKind = ...,
402 order: _OrderKACF = ...,
403 subok: bool = ...,
404 signature: str | _3Tuple[str | None] = ...,
405 ) -> _2Tuple[NDArray[Incomplete]]: ...
406 @overload
407 def __call__(
408 self,
409 x1: _SupportsArrayUFunc,
410 out1: np.ndarray | EllipsisType | None = ...,
411 out2: np.ndarray | None = ...,
412 /,
413 *,
414 out: _2Tuple[np.ndarray] | EllipsisType = ...,
415 dtype: DTypeLike | None = None,
416 where: _ArrayLikeBool_co | None = True,
417 casting: _CastingKind = ...,
418 order: _OrderKACF = ...,
419 subok: bool = ...,
420 signature: str | _3Tuple[str | None] = ...,
421 ) -> _2Tuple[Incomplete]: ...
422
423 def accumulate(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
424 def reduce(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
425 def reduceat(self, array: Never, /, indices: Never) -> NoReturn: ... # type: ignore[override]
426 def outer(self, A: Never, B: Never, /) -> NoReturn: ... # type: ignore[override]
427 def at(self, a: Never, indices: Never, /) -> NoReturn: ... # type: ignore[override]
428
429@type_check_only
430class _UFunc_Nin2_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc]
431 @property
432 def __name__(self) -> _NameType: ...
433 @property
434 def __qualname__(self) -> _NameType: ... # pyright: ignore[reportIncompatibleVariableOverride]
435 @property
436 def ntypes(self) -> _NTypes: ...
437 @property
438 def identity(self) -> _IDType: ...
439 @property
440 def nin(self) -> Literal[2]: ...
441 @property
442 def nout(self) -> Literal[2]: ...
443 @property
444 def nargs(self) -> Literal[4]: ...
445 @property
446 def signature(self) -> None: ...
447
448 @overload
449 def __call__(
450 self,
451 x1: _ScalarLike_co,
452 x2: _ScalarLike_co,
453 out1: EllipsisType | None = ...,
454 out2: None = None,
455 /,
456 *,
457 out: EllipsisType | None = ...,
458 dtype: DTypeLike | None = None,
459 where: _ArrayLikeBool_co | None = True,
460 casting: _CastingKind = ...,
461 order: _OrderKACF = ...,
462 subok: bool = ...,
463 signature: str | _4Tuple[str | None] = ...,
464 ) -> _2Tuple[Incomplete]: ...
465 @overload
466 def __call__(
467 self,
468 x1: ArrayLike,
469 x2: ArrayLike,
470 out1: np.ndarray | EllipsisType | None = ...,
471 out2: np.ndarray | None = ...,
472 /,
473 *,
474 out: _2Tuple[np.ndarray] | EllipsisType = ...,
475 dtype: DTypeLike | None = None,
476 where: _ArrayLikeBool_co | None = True,
477 casting: _CastingKind = ...,
478 order: _OrderKACF = ...,
479 subok: bool = ...,
480 signature: str | _4Tuple[str | None] = ...,
481 ) -> _2Tuple[NDArray[Incomplete]]: ...
482
483 def accumulate(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
484 def reduce(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
485 def reduceat(self, array: Never, /, indices: Never) -> NoReturn: ... # type: ignore[override]
486 def outer(self, A: Never, B: Never, /) -> NoReturn: ... # type: ignore[override]
487 def at(self, a: Never, indices: Never, b: Never, /) -> NoReturn: ... # type: ignore[override]
488
489@type_check_only
490class _GUFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType, _Signature]): # type: ignore[misc]
491 @property
492 def __name__(self) -> _NameType: ...
493 @property
494 def __qualname__(self) -> _NameType: ... # pyright: ignore[reportIncompatibleVariableOverride]
495 @property
496 def ntypes(self) -> _NTypes: ...
497 @property
498 def identity(self) -> _IDType: ...
499 @property
500 def nin(self) -> Literal[2]: ...
501 @property
502 def nout(self) -> Literal[1]: ...
503 @property
504 def nargs(self) -> Literal[3]: ...
505 @property
506 def signature(self) -> _Signature: ...
507
508 # Scalar for 1D array-likes; ndarray otherwise
509 @overload
510 def __call__(
511 self,
512 x1: ArrayLike,
513 x2: ArrayLike,
514 /,
515 out: EllipsisType | None = None,
516 *,
517 dtype: DTypeLike | None = None,
518 casting: _CastingKind = ...,
519 order: _OrderKACF = ...,
520 subok: bool = ...,
521 signature: str | _3Tuple[str | None] = ...,
522 axes: list[_2Tuple[SupportsIndex]] = ...,
523 ) -> Incomplete: ...
524 @overload
525 def __call__(
526 self,
527 x1: ArrayLike,
528 x2: ArrayLike,
529 /,
530 out: np.ndarray | tuple[np.ndarray] | EllipsisType,
531 *,
532 dtype: DTypeLike | None = None,
533 casting: _CastingKind = ...,
534 order: _OrderKACF = ...,
535 subok: bool = ...,
536 signature: str | _3Tuple[str | None] = ...,
537 axes: list[_2Tuple[SupportsIndex]] = ...,
538 ) -> NDArray[Incomplete]: ...
539
540 def accumulate(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
541 def reduce(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
542 def reduceat(self, array: Never, /, indices: Never) -> NoReturn: ... # type: ignore[override]
543 def outer(self, A: Never, B: Never, /) -> NoReturn: ... # type: ignore[override]
544 def at(self, a: Never, indices: Never, b: Never, /) -> NoReturn: ... # type: ignore[override]
545
546@type_check_only
547class _PyFunc_Kwargs_Nargs2(TypedDict, total=False):
548 where: _ArrayLikeBool_co | None
549 casting: _CastingKind
550 order: _OrderKACF
551 dtype: DTypeLike
552 subok: bool
553 signature: str | tuple[DTypeLike, DTypeLike]
554
555@type_check_only
556class _PyFunc_Kwargs_Nargs3(TypedDict, total=False):
557 where: _ArrayLikeBool_co | None
558 casting: _CastingKind
559 order: _OrderKACF
560 dtype: DTypeLike
561 subok: bool
562 signature: str | tuple[DTypeLike, DTypeLike, DTypeLike]
563
564@type_check_only
565class _PyFunc_Kwargs_Nargs3P(TypedDict, total=False):
566 where: _ArrayLikeBool_co | None
567 casting: _CastingKind
568 order: _OrderKACF
569 dtype: DTypeLike
570 subok: bool
571 signature: str | _3PTuple[DTypeLike]
572
573@type_check_only
574class _PyFunc_Kwargs_Nargs4P(TypedDict, total=False):
575 where: _ArrayLikeBool_co | None
576 casting: _CastingKind
577 order: _OrderKACF
578 dtype: DTypeLike
579 subok: bool
580 signature: str | _4PTuple[DTypeLike]
581
582@type_check_only
583class _PyFunc_Nin1_Nout1(ufunc, Generic[_ReturnType_co, _IDType]): # type: ignore[misc]
584 @property
585 def identity(self) -> _IDType: ...
586 @property
587 def nin(self) -> Literal[1]: ...
588 @property
589 def nout(self) -> Literal[1]: ...
590 @property
591 def nargs(self) -> Literal[2]: ...
592 @property
593 def ntypes(self) -> Literal[1]: ...
594 @property
595 def signature(self) -> None: ...
596
597 @overload
598 def __call__(
599 self,
600 x1: _ScalarLike_co,
601 /,
602 out: EllipsisType | None = None,
603 **kwargs: Unpack[_PyFunc_Kwargs_Nargs2],
604 ) -> _ReturnType_co: ...
605 @overload
606 def __call__(
607 self,
608 x1: ArrayLike,
609 /,
610 out: EllipsisType | None = None,
611 **kwargs: Unpack[_PyFunc_Kwargs_Nargs2],
612 ) -> _ReturnType_co | NDArray[np.object_]: ...
613 @overload
614 def __call__(
615 self,
616 x1: ArrayLike,
617 /,
618 out: _ArrayT | tuple[_ArrayT],
619 **kwargs: Unpack[_PyFunc_Kwargs_Nargs2],
620 ) -> _ArrayT: ...
621 @overload
622 def __call__(
623 self,
624 x1: _SupportsArrayUFunc,
625 /,
626 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
627 **kwargs: Unpack[_PyFunc_Kwargs_Nargs2],
628 ) -> Incomplete: ...
629
630 def accumulate(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
631 def reduce(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
632 def reduceat(self, array: Never, /, indices: Never) -> NoReturn: ... # type: ignore[override]
633 def outer(self, A: Never, B: Never, /) -> NoReturn: ... # type: ignore[override]
634
635 def at(self, a: np.ndarray | _SupportsArrayUFunc, indices: _ArrayLikeInt_co, /) -> None: ... # type: ignore[override]
636
637@type_check_only
638class _PyFunc_Nin2_Nout1(ufunc, Generic[_ReturnType_co, _IDType]): # type: ignore[misc]
639 @property
640 def identity(self) -> _IDType: ...
641 @property
642 def nin(self) -> Literal[2]: ...
643 @property
644 def nout(self) -> Literal[1]: ...
645 @property
646 def nargs(self) -> Literal[3]: ...
647 @property
648 def ntypes(self) -> Literal[1]: ...
649 @property
650 def signature(self) -> None: ...
651
652 @overload
653 def __call__(
654 self,
655 x1: _ScalarLike_co,
656 x2: _ScalarLike_co,
657 /,
658 out: EllipsisType | None = None,
659 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
660 ) -> _ReturnType_co: ...
661 @overload
662 def __call__(
663 self,
664 x1: ArrayLike,
665 x2: ArrayLike,
666 /,
667 out: EllipsisType | None = ...,
668 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
669 ) -> _ReturnType_co | NDArray[np.object_]: ...
670 @overload
671 def __call__(
672 self,
673 x1: ArrayLike,
674 x2: ArrayLike,
675 /,
676 out: _ArrayT | tuple[_ArrayT],
677 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
678 ) -> _ArrayT: ...
679 @overload
680 def __call__(
681 self,
682 x1: _SupportsArrayUFunc,
683 x2: _SupportsArrayUFunc | ArrayLike,
684 /,
685 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
686 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
687 ) -> Incomplete: ...
688 @overload
689 def __call__(
690 self,
691 x1: ArrayLike,
692 x2: _SupportsArrayUFunc,
693 /,
694 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
695 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
696 ) -> Incomplete: ...
697
698 @overload # type: ignore[override]
699 def accumulate(
700 self,
701 array: ArrayLike,
702 /,
703 axis: SupportsIndex = 0,
704 dtype: DTypeLike | None = None,
705 out: EllipsisType | None = None,
706 ) -> NDArray[np.object_]: ...
707 @overload
708 def accumulate(
709 self,
710 array: ArrayLike,
711 /,
712 axis: SupportsIndex = 0,
713 dtype: DTypeLike | None = None,
714 *,
715 out: _ArrayT,
716 ) -> _ArrayT: ...
717
718 @overload # type: ignore[override]
719 def reduce( # out=array
720 self,
721 array: ArrayLike,
722 /,
723 axis: _ShapeLike | None = 0,
724 dtype: DTypeLike | None = None,
725 *,
726 out: _ArrayT | tuple[_ArrayT],
727 keepdims: bool = False,
728 **kwargs: Unpack[_ReduceKwargs],
729 ) -> _ArrayT: ...
730 @overload # out=...
731 def reduce(
732 self,
733 array: ArrayLike,
734 /,
735 axis: _ShapeLike | None = 0,
736 dtype: DTypeLike | None = None,
737 *,
738 out: EllipsisType,
739 keepdims: bool = False,
740 **kwargs: Unpack[_ReduceKwargs],
741 ) -> NDArray[np.object_]: ...
742 @overload # keepdims=True
743 def reduce(
744 self,
745 array: ArrayLike,
746 /,
747 axis: _ShapeLike | None = 0,
748 dtype: DTypeLike | None = None,
749 out: EllipsisType | None = None,
750 *,
751 keepdims: Literal[True],
752 **kwargs: Unpack[_ReduceKwargs],
753 ) -> NDArray[np.object_]: ...
754 @overload
755 def reduce(
756 self,
757 array: ArrayLike,
758 /,
759 axis: _ShapeLike | None = 0,
760 dtype: DTypeLike | None = None,
761 out: EllipsisType | None = None,
762 keepdims: bool = False,
763 **kwargs: Unpack[_ReduceKwargs],
764 ) -> _ReturnType_co | NDArray[np.object_]: ...
765
766 @overload # type: ignore[override]
767 def reduceat(
768 self,
769 array: ArrayLike,
770 /,
771 indices: _ArrayLikeInt_co,
772 axis: SupportsIndex = 0,
773 dtype: DTypeLike | None = None,
774 *,
775 out: _ArrayT | tuple[_ArrayT],
776 ) -> _ArrayT: ...
777 @overload
778 def reduceat(
779 self,
780 array: ArrayLike,
781 /,
782 indices: _ArrayLikeInt_co,
783 axis: SupportsIndex = 0,
784 dtype: DTypeLike | None = None,
785 out: EllipsisType | None = None,
786 ) -> NDArray[np.object_]: ...
787 @overload
788 def reduceat(
789 self,
790 array: _SupportsArrayUFunc,
791 /,
792 indices: _ArrayLikeInt_co,
793 axis: SupportsIndex = 0,
794 dtype: DTypeLike | None = None,
795 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = None,
796 ) -> Incomplete: ...
797
798 @overload # type: ignore[override]
799 def outer(
800 self,
801 A: _ScalarLike_co,
802 B: _ScalarLike_co,
803 /,
804 *,
805 out: EllipsisType | None = None,
806 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
807 ) -> _ReturnType_co: ...
808 @overload
809 def outer(
810 self,
811 A: ArrayLike,
812 B: ArrayLike,
813 /,
814 *,
815 out: EllipsisType | None = None,
816 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
817 ) -> _ReturnType_co | NDArray[np.object_]: ...
818 @overload
819 def outer(
820 self,
821 A: ArrayLike,
822 B: ArrayLike,
823 /,
824 *,
825 out: _ArrayT,
826 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
827 ) -> _ArrayT: ...
828 @overload
829 def outer(
830 self,
831 A: _SupportsArrayUFunc,
832 B: _SupportsArrayUFunc | ArrayLike,
833 /,
834 *,
835 out: EllipsisType | None = None,
836 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
837 ) -> Incomplete: ...
838 @overload
839 def outer(
840 self,
841 A: _ScalarLike_co,
842 B: _SupportsArrayUFunc | ArrayLike,
843 /,
844 *,
845 out: EllipsisType | None = None,
846 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3],
847 ) -> Incomplete: ...
848
849 def at( # type: ignore[override]
850 self,
851 a: np.ndarray | _SupportsArrayUFunc,
852 indices: _ArrayLikeInt_co,
853 b: ArrayLike,
854 /,
855 ) -> None: ...
856
857@type_check_only
858class _PyFunc_Nin3P_Nout1(ufunc, Generic[_ReturnType_co, _IDType, _NIn]): # type: ignore[misc]
859 @property
860 def identity(self) -> _IDType: ...
861 @property
862 def nin(self) -> _NIn: ...
863 @property
864 def nout(self) -> Literal[1]: ...
865 @property
866 def ntypes(self) -> Literal[1]: ...
867 @property
868 def signature(self) -> None: ...
869
870 @overload
871 def __call__(
872 self,
873 x1: _ScalarLike_co,
874 x2: _ScalarLike_co,
875 x3: _ScalarLike_co,
876 /,
877 *xs: _ScalarLike_co,
878 out: EllipsisType | None = ...,
879 **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P],
880 ) -> _ReturnType_co: ...
881 @overload
882 def __call__(
883 self,
884 x1: ArrayLike,
885 x2: ArrayLike,
886 x3: ArrayLike,
887 /,
888 *xs: ArrayLike,
889 out: EllipsisType | None = ...,
890 **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P],
891 ) -> _ReturnType_co | NDArray[np.object_]: ...
892 @overload
893 def __call__(
894 self,
895 x1: ArrayLike,
896 x2: ArrayLike,
897 x3: ArrayLike,
898 /,
899 *xs: ArrayLike,
900 out: _ArrayT | tuple[_ArrayT],
901 **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P],
902 ) -> _ArrayT: ...
903 @overload
904 def __call__(
905 self,
906 x1: _SupportsArrayUFunc | ArrayLike,
907 x2: _SupportsArrayUFunc | ArrayLike,
908 x3: _SupportsArrayUFunc | ArrayLike,
909 /,
910 *xs: _SupportsArrayUFunc | ArrayLike,
911 out: np.ndarray | tuple[np.ndarray] | EllipsisType | None = ...,
912 **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P],
913 ) -> Incomplete: ...
914
915 def accumulate(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
916 def reduce(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
917 def reduceat(self, array: Never, /, indices: Never) -> NoReturn: ... # type: ignore[override]
918 def outer(self, A: Never, B: Never, /) -> NoReturn: ... # type: ignore[override]
919 def at(self, a: Never, indices: Never, /, *args: Never) -> NoReturn: ... # type: ignore[override]
920
921@type_check_only
922class _PyFunc_Nin1P_Nout2P(ufunc, Generic[_ReturnType_co, _IDType, _NIn, _NOut]): # type: ignore[misc]
923 @property
924 def identity(self) -> _IDType: ...
925 @property
926 def nin(self) -> _NIn: ...
927 @property
928 def nout(self) -> _NOut: ...
929 @property
930 def ntypes(self) -> Literal[1]: ...
931 @property
932 def signature(self) -> None: ...
933
934 @overload
935 def __call__(
936 self,
937 x1: _ScalarLike_co,
938 /,
939 *xs: _ScalarLike_co,
940 out: EllipsisType | None = ...,
941 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P],
942 ) -> _2PTuple[_ReturnType_co]: ...
943 @overload
944 def __call__(
945 self,
946 x1: ArrayLike,
947 /,
948 *xs: ArrayLike,
949 out: EllipsisType | None = ...,
950 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P],
951 ) -> _2PTuple[_ReturnType_co | NDArray[np.object_]]: ...
952 @overload
953 def __call__(
954 self,
955 x1: ArrayLike,
956 /,
957 *xs: ArrayLike,
958 out: _2PTuple[_ArrayT],
959 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P],
960 ) -> _2PTuple[_ArrayT]: ...
961 @overload
962 def __call__(
963 self,
964 x1: _SupportsArrayUFunc | ArrayLike,
965 /,
966 *xs: _SupportsArrayUFunc | ArrayLike,
967 out: _2PTuple[np.ndarray] | EllipsisType | None = ...,
968 **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P],
969 ) -> Incomplete: ...
970
971 def accumulate(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
972 def reduce(self, array: Never, /) -> NoReturn: ... # type: ignore[override]
973 def reduceat(self, array: Never, /, indices: Never) -> NoReturn: ... # type: ignore[override]
974 def outer(self, A: Never, B: Never, /) -> NoReturn: ... # type: ignore[override]
975 def at(self, a: Never, indices: Never, /, *args: Never) -> NoReturn: ... # type: ignore[override]
976 