_ufunc.pyi 29 KB

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