From 650c5cb72f1c251d1ee5dc01aa7bac1e2a832b5d Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 02:26:44 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20complete=20ufunc=20infrastructu?= =?UTF-8?q?re=20rewrite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .mypyignore-todo | 54 - src/numpy-stubs/__init__.pyi | 302 ++-- src/numpy-stubs/_core/_multiarray_umath.pyi | 103 +- src/numpy-stubs/_typing/__init__.pyi | 7 - src/numpy-stubs/_typing/_ufunc.pyi | 1431 ++++++++++--------- src/numpy-stubs/matlib.pyi | 1 + test/static/accept/multiarray.pyi | 164 +-- test/static/accept/ufuncs.pyi | 91 +- test/static/reject/ufuncs.pyi | 24 + 9 files changed, 1073 insertions(+), 1104 deletions(-) diff --git a/.mypyignore-todo b/.mypyignore-todo index e9b9656a..ce1f8195 100644 --- a/.mypyignore-todo +++ b/.mypyignore-todo @@ -8,60 +8,6 @@ numpy(\..+)?\.floating.as_integer_ratio numpy(\..+)?\.complexfloating.__hash__ numpy(\..+)?\.complexfloating.__complex__ -# https://github.com/numpy/numtype/issues/88 -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.f?abs(olute)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.ceil -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.trunc -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.rint -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.add -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.subtract -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(a(rc)?)?cosh? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(a(rc)?)?sinh? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(a(rc)?)?tanh? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(a(rc)?)?tan2 -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.invert -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.bitwise_(count|invert) -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.bitwise_(not|and|x?or) -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.logical_(not|and|x?or) -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(bitwise_)?(left|right)_shift -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.conj(ugate)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.divmod -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.multiply -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(true_)?divide -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.floor(_divide)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.f(min|max) -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.frexp -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.gcd -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.lcm -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(not_)?equal -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.greater(_equal)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.less(_equal)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.heaviside -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.hypot -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.is(finite|inf|nan|nat) -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(ld)?exp(2|m1)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.log(2|10|1p)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.logaddexp2? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.mat(vec|mul) -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(min|max)imum -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.f?modf? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.positive -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.negative -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.nextafter -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(float_)?pow(er)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.deg2rad -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.rad2deg -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.degrees -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.radians -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.reciprocal -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.remainder -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.(copy)?sign(bit)? -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.spacing -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.square -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.sqrt -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.cbrt -numpy(\._core(\.(_multiarray_umath|multiarray|numeric|umath))?|\.matlib)?\.vec(dot|mat) - numpy(\._core(\.arrayprint|\.numeric)?|\.matlib)?\.array2string numpy(\._core(\.einsumfunc)?|\.matlib)?\.einsum_path numpy(\._core(\.memmap)?|\.matlib)?\.memmap\.__new__ diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index 542f778d..fc4d419e 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -11,6 +11,7 @@ from types import EllipsisType, GenericAlias, GetSetDescriptorType, MappingProxy from typing import ( Any, ClassVar, + Concatenate, Final, Generic, Literal as L, @@ -96,6 +97,7 @@ from ._core import ( choose, clip, compress, + concat, concatenate, convolve, copyto, @@ -168,6 +170,7 @@ from ._core import ( ones_like, outer, partition, + permute_dims, pi, printoptions, prod, @@ -249,7 +252,6 @@ from ._typing import ( _ComplexFloatingCodes, _DTypeLike, _DTypeLikeVoid, - _GUFunc_Nin2_Nout1, _IntLike_co, _NBitIntP, _NBitLong, @@ -260,10 +262,6 @@ from ._typing import ( _ScalarLike_co, _ShapeLike, _TD64Like_co, - _UFunc_Nin1_Nout1, - _UFunc_Nin1_Nout2, - _UFunc_Nin2_Nout1, - _UFunc_Nin2_Nout2, _VoidDTypeLike, ) from ._typing._callable import ( @@ -321,8 +319,7 @@ from ._typing._char_codes import ( _UnsignedIntegerCodes, _VoidCodes, ) - -# TODO(jorenham): remove these: https://github.com/numpy/numtype/issues/120 +from ._typing._ufunc import _gufunc_2_1, _ufunc_1_1, _ufunc_1_2, _ufunc_2_1, _ufunc_2_2 from .lib import scimath as emath from .lib._arraypad_impl import pad from .lib._arraysetops_impl import ( @@ -6619,12 +6616,56 @@ cdouble = complex128 ### # ufuncs (s See `numpy._typing._ufunc` for more concrete nin-/nout-specific stubs) +_CallT_co = TypeVar( + "_CallT_co", + bound=Callable[Concatenate[Never, ...], object], + default=Callable[Concatenate[Any, ...], Any], + covariant=True, +) +_AtT_co = TypeVar( + "_AtT_co", + bound=Callable[Concatenate[Never, Never, ...], None], + default=Callable[Concatenate[Any, Any, ...], None], + covariant=True, +) +_ReduceT_co = TypeVar( + "_ReduceT_co", + bound=Callable[Concatenate[Never, ...], object], + default=Callable[Concatenate[Any, ...], Any], + covariant=True, +) +_ReduceAtT_co = TypeVar( + "_ReduceAtT_co", + bound=Callable[Concatenate[Never, Never, ...], object], + default=Callable[Concatenate[Any, Any, ...], NDArray[Any]], + covariant=True, +) +_AccumulateT_co = TypeVar( + "_AccumulateT_co", + bound=Callable[Concatenate[Never, ...], object], + default=Callable[Concatenate[Any, ...], NDArray[Any]], + covariant=True, +) +_OuterT_co = TypeVar( + "_OuterT_co", + bound=Callable[Concatenate[Never, Never, ...], object], + default=Callable[Concatenate[Any, Any, ...], Any], + covariant=True, +) + @final -class ufunc: +class ufunc(Generic[_CallT_co, _AtT_co, _ReduceT_co, _ReduceAtT_co, _AccumulateT_co, _OuterT_co]): + __call__: _CallT_co # method + at: _AtT_co # method + reduce: _ReduceT_co # method + reduceat: _ReduceAtT_co # method + accumulate: _AccumulateT_co # method + outer: _OuterT_co # method + @property - def __name__(self) -> LiteralString: ... + def __name__(self) -> str: ... @property - def __qualname__(self) -> LiteralString: ... # pyright: ignore[reportIncompatibleVariableOverride] + def __qualname__(self) -> str: ... # pyright: ignore[reportIncompatibleVariableOverride] @property def __doc__(self) -> str: ... # type: ignore[override] # pyright: ignore[reportIncompatibleVariableOverride] @@ -6638,19 +6679,11 @@ class ufunc: @property def ntypes(self) -> int: ... @property - def types(self) -> list[LiteralString]: ... - @property - def identity(self) -> Any: ... + def types(self) -> list[str]: ... + @property # in numpy this is one of `{0, -1, -inf, True, None}` + def identity(self) -> Any | None: ... @property - def signature(self) -> LiteralString | None: ... - - # - def __call__(self, /, *args: Any, **kwargs: Any) -> Any: ... - def reduce(self, /, *args: Any, **kwargs: Any) -> Any: ... - def accumulate(self, /, *args: Any, **kwargs: Any) -> NDArray[Any]: ... - def reduceat(self, /, *args: Any, **kwargs: Any) -> NDArray[Any]: ... - def outer(self, *args: Any, **kwargs: Any) -> Any: ... - def at(self, /, *args: Any, **kwargs: Any) -> None: ... + def signature(self) -> str | None: ... # def resolve_dtypes( @@ -6663,116 +6696,115 @@ class ufunc: reduction: py_bool = False, ) -> tuple[dtype[Any], ...]: ... -absolute: Final[_UFunc_Nin1_Nout1[L["absolute"], L[20]]] = ... -arccos: Final[_UFunc_Nin1_Nout1[L["arccos"], L[8]]] = ... -arccosh: Final[_UFunc_Nin1_Nout1[L["arccosh"], L[8]]] = ... -arcsin: Final[_UFunc_Nin1_Nout1[L["arcsin"], L[8]]] = ... -arcsinh: Final[_UFunc_Nin1_Nout1[L["arcsinh"], L[8]]] = ... -arctan: Final[_UFunc_Nin1_Nout1[L["arctan"], L[8]]] = ... -arctanh: Final[_UFunc_Nin1_Nout1[L["arctanh"], L[8]]] = ... -bitwise_count: Final[_UFunc_Nin1_Nout1[L["bitwise_count"], L[11]]] = ... -bitwise_not: Final[_UFunc_Nin1_Nout1[L["invert"], L[12]]] = ... -cbrt: Final[_UFunc_Nin1_Nout1[L["cbrt"], L[5]]] = ... -ceil: Final[_UFunc_Nin1_Nout1[L["ceil"], L[7]]] = ... -conj: Final[_UFunc_Nin1_Nout1[L["conjugate"], L[18]]] = ... -conjugate: Final[_UFunc_Nin1_Nout1[L["conjugate"], L[18]]] = ... -cos: Final[_UFunc_Nin1_Nout1[L["cos"], L[9]]] = ... -cosh: Final[_UFunc_Nin1_Nout1[L["cosh"], L[8]]] = ... -deg2rad: Final[_UFunc_Nin1_Nout1[L["deg2rad"], L[5]]] = ... -degrees: Final[_UFunc_Nin1_Nout1[L["degrees"], L[5]]] = ... -exp2: Final[_UFunc_Nin1_Nout1[L["exp2"], L[8]]] = ... -exp: Final[_UFunc_Nin1_Nout1[L["exp"], L[10]]] = ... -expm1: Final[_UFunc_Nin1_Nout1[L["expm1"], L[8]]] = ... -fabs: Final[_UFunc_Nin1_Nout1[L["fabs"], L[5]]] = ... -floor: Final[_UFunc_Nin1_Nout1[L["floor"], L[7]]] = ... -invert: Final[_UFunc_Nin1_Nout1[L["invert"], L[12]]] = ... -isfinite: Final[_UFunc_Nin1_Nout1[L["isfinite"], L[20]]] = ... -isinf: Final[_UFunc_Nin1_Nout1[L["isinf"], L[20]]] = ... -isnan: Final[_UFunc_Nin1_Nout1[L["isnan"], L[20]]] = ... -isnat: Final[_UFunc_Nin1_Nout1[L["isnat"], L[2]]] = ... -log10: Final[_UFunc_Nin1_Nout1[L["log10"], L[8]]] = ... -log1p: Final[_UFunc_Nin1_Nout1[L["log1p"], L[8]]] = ... -log2: Final[_UFunc_Nin1_Nout1[L["log2"], L[8]]] = ... -log: Final[_UFunc_Nin1_Nout1[L["log"], L[10]]] = ... -logical_not: Final[_UFunc_Nin1_Nout1[L["logical_not"], L[20]]] = ... -negative: Final[_UFunc_Nin1_Nout1[L["negative"], L[19]]] = ... -positive: Final[_UFunc_Nin1_Nout1[L["positive"], L[19]]] = ... -rad2deg: Final[_UFunc_Nin1_Nout1[L["rad2deg"], L[5]]] = ... -radians: Final[_UFunc_Nin1_Nout1[L["radians"], L[5]]] = ... -reciprocal: Final[_UFunc_Nin1_Nout1[L["reciprocal"], L[18]]] = ... -rint: Final[_UFunc_Nin1_Nout1[L["rint"], L[10]]] = ... -sign: Final[_UFunc_Nin1_Nout1[L["sign"], L[19]]] = ... -signbit: Final[_UFunc_Nin1_Nout1[L["signbit"], L[4]]] = ... -sin: Final[_UFunc_Nin1_Nout1[L["sin"], L[9]]] = ... -sinh: Final[_UFunc_Nin1_Nout1[L["sinh"], L[8]]] = ... -spacing: Final[_UFunc_Nin1_Nout1[L["spacing"], L[4]]] = ... -sqrt: Final[_UFunc_Nin1_Nout1[L["sqrt"], L[10]]] = ... -square: Final[_UFunc_Nin1_Nout1[L["square"], L[18]]] = ... -tan: Final[_UFunc_Nin1_Nout1[L["tan"], L[8]]] = ... -tanh: Final[_UFunc_Nin1_Nout1[L["tanh"], L[8]]] = ... -trunc: Final[_UFunc_Nin1_Nout1[L["trunc"], L[7]]] = ... - -add: Final[_UFunc_Nin2_Nout1[L["add"], L[22], L[0]]] = ... -arctan2: Final[_UFunc_Nin2_Nout1[L["arctan2"], L[5]]] = ... -bitwise_and: Final[_UFunc_Nin2_Nout1[L["bitwise_and"], L[12], L[-1]]] = ... -bitwise_or: Final[_UFunc_Nin2_Nout1[L["bitwise_or"], L[12], L[0]]] = ... -bitwise_xor: Final[_UFunc_Nin2_Nout1[L["bitwise_xor"], L[12], L[0]]] = ... -copysign: Final[_UFunc_Nin2_Nout1[L["copysign"], L[4]]] = ... -divide: Final[_UFunc_Nin2_Nout1[L["true_divide"], L[11]]] = ... -equal: Final[_UFunc_Nin2_Nout1[L["equal"], L[23]]] = ... -float_power: Final[_UFunc_Nin2_Nout1[L["float_power"], L[4]]] = ... -floor_divide: Final[_UFunc_Nin2_Nout1[L["floor_divide"], L[21]]] = ... -fmax: Final[_UFunc_Nin2_Nout1[L["fmax"], L[21]]] = ... -fmin: Final[_UFunc_Nin2_Nout1[L["fmin"], L[21]]] = ... -fmod: Final[_UFunc_Nin2_Nout1[L["fmod"], L[15]]] = ... -gcd: Final[_UFunc_Nin2_Nout1[L["gcd"], L[11], L[0]]] = ... -greater: Final[_UFunc_Nin2_Nout1[L["greater"], L[23]]] = ... -greater_equal: Final[_UFunc_Nin2_Nout1[L["greater_equal"], L[23]]] = ... -heaviside: Final[_UFunc_Nin2_Nout1[L["heaviside"], L[4]]] = ... -hypot: Final[_UFunc_Nin2_Nout1[L["hypot"], L[5], L[0]]] = ... -lcm: Final[_UFunc_Nin2_Nout1[L["lcm"], L[11]]] = ... -ldexp: Final[_UFunc_Nin2_Nout1[L["ldexp"], L[8]]] = ... -left_shift: Final[_UFunc_Nin2_Nout1[L["left_shift"], L[11]]] = ... -less: Final[_UFunc_Nin2_Nout1[L["less"], L[23]]] = ... -less_equal: Final[_UFunc_Nin2_Nout1[L["less_equal"], L[23]]] = ... -logaddexp2: Final[_UFunc_Nin2_Nout1[L["logaddexp2"], L[4], float]] = ... -logaddexp: Final[_UFunc_Nin2_Nout1[L["logaddexp"], L[4], float]] = ... -logical_and: Final[_UFunc_Nin2_Nout1[L["logical_and"], L[20], L[True]]] = ... -logical_or: Final[_UFunc_Nin2_Nout1[L["logical_or"], L[20], L[False]]] = ... -logical_xor: Final[_UFunc_Nin2_Nout1[L["logical_xor"], L[19], L[False]]] = ... -maximum: Final[_UFunc_Nin2_Nout1[L["maximum"], L[21]]] = ... -minimum: Final[_UFunc_Nin2_Nout1[L["minimum"], L[21]]] = ... -mod: Final[_UFunc_Nin2_Nout1[L["remainder"], L[16]]] = ... -multiply: Final[_UFunc_Nin2_Nout1[L["multiply"], L[23], L[1]]] = ... -nextafter: Final[_UFunc_Nin2_Nout1[L["nextafter"], L[4]]] = ... -not_equal: Final[_UFunc_Nin2_Nout1[L["not_equal"], L[23]]] = ... -power: Final[_UFunc_Nin2_Nout1[L["power"], L[18]]] = ... -remainder: Final[_UFunc_Nin2_Nout1[L["remainder"], L[16]]] = ... -right_shift: Final[_UFunc_Nin2_Nout1[L["right_shift"], L[11]]] = ... -subtract: Final[_UFunc_Nin2_Nout1[L["subtract"], L[21]]] = ... -true_divide: Final[_UFunc_Nin2_Nout1[L["true_divide"], L[11]]] = ... - -matmul: Final[_GUFunc_Nin2_Nout1[L["matmul"], L[19], None, L["(n?,k),(k,m?)->(n?,m?)"]]] = ... -matvec: Final[_GUFunc_Nin2_Nout1[L["matvec"], L[19], None, L["(m,n),(n)->(m)"]]] = ... -vecdot: Final[_GUFunc_Nin2_Nout1[L["vecdot"], L[19], None, L["(n),(n)->()"]]] = ... -vecmat: Final[_GUFunc_Nin2_Nout1[L["vecmat"], L[19], None, L["(n),(n,m)->(m)"]]] = ... - -frexp: Final[_UFunc_Nin1_Nout2[L["frexp"], L[4]]] = ... -modf: Final[_UFunc_Nin1_Nout2[L["modf"], L[4]]] = ... - -divmod: Final[_UFunc_Nin2_Nout2[L["divmod"], L[15]]] = ... - -abs: Final = absolute -acos: Final = arccos -acosh: Final = arccosh -asin: Final = arcsin -asinh: Final = arcsinh -atan: Final = arctan -atanh: Final = arctanh -atan2: Final = arctan2 -concat: Final = concatenate -bitwise_left_shift: Final = left_shift -bitwise_invert: Final = invert -bitwise_right_shift: Final = right_shift -permute_dims: Final = transpose -pow: Final = power +# TODO(jorenham): individually annotate each of the ufunc signatures + +absolute: Final[_ufunc_1_1] = ... +arccos: Final[_ufunc_1_1] = ... +arccosh: Final[_ufunc_1_1] = ... +arcsin: Final[_ufunc_1_1] = ... +arcsinh: Final[_ufunc_1_1] = ... +arctan: Final[_ufunc_1_1] = ... +arctanh: Final[_ufunc_1_1] = ... +bitwise_count: Final[_ufunc_1_1] = ... +cbrt: Final[_ufunc_1_1] = ... +ceil: Final[_ufunc_1_1] = ... +conjugate: Final[_ufunc_1_1] = ... +cos: Final[_ufunc_1_1] = ... +cosh: Final[_ufunc_1_1] = ... +deg2rad: Final[_ufunc_1_1] = ... +degrees: Final[_ufunc_1_1] = ... +exp: Final[_ufunc_1_1] = ... +exp2: Final[_ufunc_1_1] = ... +expm1: Final[_ufunc_1_1] = ... +fabs: Final[_ufunc_1_1] = ... +floor: Final[_ufunc_1_1] = ... +invert: Final[_ufunc_1_1] = ... +isfinite: Final[_ufunc_1_1] = ... +isinf: Final[_ufunc_1_1] = ... +isnan: Final[_ufunc_1_1] = ... +isnat: Final[_ufunc_1_1] = ... +log: Final[_ufunc_1_1] = ... +log2: Final[_ufunc_1_1] = ... +log10: Final[_ufunc_1_1] = ... +log1p: Final[_ufunc_1_1] = ... +logical_not: Final[_ufunc_1_1] = ... +negative: Final[_ufunc_1_1] = ... +positive: Final[_ufunc_1_1] = ... +rad2deg: Final[_ufunc_1_1] = ... +radians: Final[_ufunc_1_1] = ... +reciprocal: Final[_ufunc_1_1] = ... +rint: Final[_ufunc_1_1] = ... +sign: Final[_ufunc_1_1] = ... +signbit: Final[_ufunc_1_1] = ... +sin: Final[_ufunc_1_1] = ... +sinh: Final[_ufunc_1_1] = ... +spacing: Final[_ufunc_1_1] = ... +sqrt: Final[_ufunc_1_1] = ... +square: Final[_ufunc_1_1] = ... +tan: Final[_ufunc_1_1] = ... +tanh: Final[_ufunc_1_1] = ... +trunc: Final[_ufunc_1_1] = ... +abs = absolute +acos = arccos +acosh = arccosh +asin = arcsin +asinh = arcsinh +atan = arctan +atanh = arctanh +bitwise_not = invert +bitwise_invert = invert +conj = conjugate + +frexp: Final[_ufunc_1_2] = ... +modf: Final[_ufunc_1_2] = ... + +add: Final[_ufunc_2_1] = ... +arctan2: Final[_ufunc_2_1] = ... +bitwise_and: Final[_ufunc_2_1] = ... +bitwise_or: Final[_ufunc_2_1] = ... +bitwise_xor: Final[_ufunc_2_1] = ... +copysign: Final[_ufunc_2_1] = ... +divide: Final[_ufunc_2_1] = ... +equal: Final[_ufunc_2_1] = ... +float_power: Final[_ufunc_2_1] = ... +floor_divide: Final[_ufunc_2_1] = ... +fmax: Final[_ufunc_2_1] = ... +fmin: Final[_ufunc_2_1] = ... +fmod: Final[_ufunc_2_1] = ... +gcd: Final[_ufunc_2_1] = ... +greater: Final[_ufunc_2_1] = ... +greater_equal: Final[_ufunc_2_1] = ... +heaviside: Final[_ufunc_2_1] = ... +hypot: Final[_ufunc_2_1] = ... +lcm: Final[_ufunc_2_1] = ... +ldexp: Final[_ufunc_2_1] = ... +left_shift: Final[_ufunc_2_1] = ... +less: Final[_ufunc_2_1] = ... +less_equal: Final[_ufunc_2_1] = ... +logaddexp: Final[_ufunc_2_1] = ... +logaddexp2: Final[_ufunc_2_1] = ... +logical_and: Final[_ufunc_2_1] = ... +logical_or: Final[_ufunc_2_1] = ... +logical_xor: Final[_ufunc_2_1] = ... +maximum: Final[_ufunc_2_1] = ... +minimum: Final[_ufunc_2_1] = ... +mod: Final[_ufunc_2_1] = ... +multiply: Final[_ufunc_2_1] = ... +nextafter: Final[_ufunc_2_1] = ... +not_equal: Final[_ufunc_2_1] = ... +power: Final[_ufunc_2_1] = ... +remainder: Final[_ufunc_2_1] = ... +right_shift: Final[_ufunc_2_1] = ... +subtract: Final[_ufunc_2_1] = ... +atan2 = arctan2 +bitwise_left_shift = left_shift +bitwise_right_shift = right_shift +pow = power +true_divide = divide + +divmod: Final[_ufunc_2_2] = ... + +matmul: Final[_gufunc_2_1] = ... # (n?, k), (k, m?) -> (n?, m?) +matvec: Final[_gufunc_2_1] = ... # (m, n), (n) -> (m) +vecmat: Final[_gufunc_2_1] = ... # (n), (n, m) -> (m) +vecdot: Final[_gufunc_2_1] = ... # (n), (n) -> () diff --git a/src/numpy-stubs/_core/_multiarray_umath.pyi b/src/numpy-stubs/_core/_multiarray_umath.pyi index a1a9142e..103b0b30 100644 --- a/src/numpy-stubs/_core/_multiarray_umath.pyi +++ b/src/numpy-stubs/_core/_multiarray_umath.pyi @@ -143,11 +143,13 @@ from numpy._typing import ( _SupportsArrayFunc, ) from numpy._typing._ufunc import ( - _PyFunc_Nin1P_Nout2 as _PyFunc1P2, - _PyFunc_Nin1P_Nout2P as _PyFunc1P2P, - _PyFunc_Nin1_Nout1 as _PyFunc11, - _PyFunc_Nin2_Nout1 as _PyFunc21, - _PyFunc_Nin3P_Nout1 as _PyFunc3P1, + _pyfunc_1_1, + _pyfunc_1n_2, + _pyfunc_1n_2n, + _pyfunc_2_1, + _pyfunc_3n_1, + _ufunc_1_1, + _ufunc_2_1, ) ### @@ -156,7 +158,6 @@ _T = TypeVar("_T") _T_contra = TypeVar("_T_contra", default=None, contravariant=True) _T1 = TypeVar("_T1") _T2 = TypeVar("_T2") -_IdT = TypeVar("_IdT", default=None) _ShapeT = TypeVar("_ShapeT", bound=tuple[int, ...]) _ShapeT0 = TypeVar("_ShapeT0", bound=tuple[int, ...], default=tuple[int, ...]) @@ -398,44 +399,52 @@ e: Final[float] = ... euler_gamma: Final[float] = ... pi: Final[float] = ... +# 1->1 +isalnum: _ufunc_1_1 +isalpha: _ufunc_1_1 +isdecimal: _ufunc_1_1 +isdigit: _ufunc_1_1 +islower: _ufunc_1_1 +isnumeric: _ufunc_1_1 +isspace: _ufunc_1_1 +istitle: _ufunc_1_1 +isupper: _ufunc_1_1 +str_len: _ufunc_1_1 +_arg: _ufunc_1_1 +_ones_like: _ufunc_1_1 +_lstrip_whitespace: _ufunc_1_1 +_rstrip_whitespace: _ufunc_1_1 +_strip_whitespace: _ufunc_1_1 + +# 2->1 +_expandtabs: _ufunc_2_1 +_expandtabs_length: _ufunc_2_1 +_lstrip_chars: _ufunc_2_1 +_rstrip_chars: _ufunc_2_1 +_strip_chars: _ufunc_2_1 +_zfill: _ufunc_2_1 + +# 3->1 clip: np.ufunc +_center: np.ufunc +_ljust: np.ufunc +_rjust: np.ufunc + +# 3->3 +_partition_index: np.ufunc +_rpartition_index: np.ufunc + +# 4->1 count: np.ufunc endswith: np.ufunc +startswith: np.ufunc find: np.ufunc -index: np.ufunc -isalnum: np.ufunc -isalpha: np.ufunc -isdecimal: np.ufunc -isdigit: np.ufunc -islower: np.ufunc -isnumeric: np.ufunc -isspace: np.ufunc -istitle: np.ufunc -isupper: np.ufunc rfind: np.ufunc +index: np.ufunc rindex: np.ufunc -startswith: np.ufunc -str_len: np.ufunc - -_arg: np.ufunc -_center: np.ufunc -_expandtabs: np.ufunc -_expandtabs_length: np.ufunc -_ljust: np.ufunc -_lstrip_chars: np.ufunc -_lstrip_whitespace: np.ufunc -_ones_like: np.ufunc _partition: np.ufunc -_partition_index: np.ufunc -_replace: np.ufunc -_rjust: np.ufunc _rpartition: np.ufunc -_rpartition_index: np.ufunc -_rstrip_chars: np.ufunc -_rstrip_whitespace: np.ufunc -_strip_chars: np.ufunc -_strip_whitespace: np.ufunc -_zfill: np.ufunc +_replace: np.ufunc @final class flagsobj: @@ -1757,19 +1766,11 @@ def format_longfloat(*args: Incomplete, **kwargs: Incomplete) -> Incomplete: ... # NOTE: We can't use e.g. `Concatenate[Any, ...]`, as that causes mypy to reject every function... @overload # (a) -> T -def frompyfunc(f: Callable[[Any], _T], /, nin: _1, nout: _1, *, identity: _IdT | None = None) -> _PyFunc11[_T, _IdT]: ... +def frompyfunc(f: Callable[[Any], _T], /, nin: _1, nout: _1, *, identity: object = None) -> _pyfunc_1_1[_T]: ... @overload # (a, b) -> T -def frompyfunc(f: Callable[[Any, Any], _T], /, nin: _2, nout: _1, *, identity: _IdT | None = None) -> _PyFunc21[_T, _IdT]: ... +def frompyfunc(f: Callable[[Any, Any], _T], /, nin: _2, nout: _1, *, identity: object = None) -> _pyfunc_2_1[_T]: ... @overload # (a, b, c, ...) -> T -def frompyfunc( - # f: Callable[Concatenate[Any, Any, Any, ...], _T], - f: Callable[..., _T], - /, - nin: _3P, - nout: _1, - *, - identity: _IdT | None = None, -) -> _PyFunc3P1[_T, _IdT]: ... +def frompyfunc(f: Callable[..., _T], /, nin: _3P, nout: _1, *, identity: object = None) -> _pyfunc_3n_1[_T]: ... @overload # (a, ...) -> (T1, T2) def frompyfunc( # type: ignore[overload-overlap] # mypy-only false positive f: Callable[..., tuple[_T1, _T2]], @@ -1777,8 +1778,8 @@ def frompyfunc( # type: ignore[overload-overlap] # mypy-only false positive nin: _1P, nout: _2, *, - identity: _IdT | None = None, -) -> _PyFunc1P2[_T1, _T2, _IdT]: ... + identity: object = None, +) -> _pyfunc_1n_2[_T1, _T2]: ... @overload # (a, ...) -> (T1, T2, *(T, ...)) def frompyfunc( f: Callable[..., tuple[_T1, _T2, Unpack[tuple[_T, ...]]]], @@ -1786,8 +1787,8 @@ def frompyfunc( nin: _1P, nout: _2P, *, - identity: _IdT | None = None, -) -> _PyFunc1P2P[_T1 | _T2 | _T, _IdT]: ... + identity: object = None, +) -> _pyfunc_1n_2n[_T1 | _T2 | _T]: ... @overload def frompyfunc(f: Callable[..., Any], /, nin: SupportsIndex, nout: SupportsIndex, *, identity: object = None) -> np.ufunc: ... diff --git a/src/numpy-stubs/_typing/__init__.pyi b/src/numpy-stubs/_typing/__init__.pyi index 01371333..63ae8798 100644 --- a/src/numpy-stubs/_typing/__init__.pyi +++ b/src/numpy-stubs/_typing/__init__.pyi @@ -124,10 +124,3 @@ from ._scalars import ( _VoidLike_co as _VoidLike_co, ) from ._shape import _Shape as _Shape, _ShapeLike as _ShapeLike -from ._ufunc import ( - _GUFunc_Nin2_Nout1 as _GUFunc_Nin2_Nout1, - _UFunc_Nin1_Nout1 as _UFunc_Nin1_Nout1, - _UFunc_Nin1_Nout2 as _UFunc_Nin1_Nout2, - _UFunc_Nin2_Nout1 as _UFunc_Nin2_Nout1, - _UFunc_Nin2_Nout2 as _UFunc_Nin2_Nout2, -) diff --git a/src/numpy-stubs/_typing/_ufunc.pyi b/src/numpy-stubs/_typing/_ufunc.pyi index a9b8691b..0fcadfdb 100644 --- a/src/numpy-stubs/_typing/_ufunc.pyi +++ b/src/numpy-stubs/_typing/_ufunc.pyi @@ -1,8 +1,8 @@ +from collections.abc import Callable, Sequence from typing import ( Any, - Generic, - Literal, - NoReturn, + Concatenate, + Literal as L, Protocol, SupportsIndex, TypeAlias, @@ -10,801 +10,663 @@ from typing import ( overload, type_check_only, ) -from typing_extensions import LiteralString, TypeVar, Unpack +from typing_extensions import Never, TypeAliasType, TypeVar, Unpack import numpy as np -import numpy.typing as npt +from numpy import _CastingKind, _OrderKACF # noqa: ICN003 -from ._array_like import ArrayLike, _ArrayLikeBool_co, _ArrayLikeInt_co -from ._dtype_like import DTypeLike +from ._array_like import ArrayLike, NDArray, _ArrayLikeBool_co, _ArrayLikeInt_co +from ._dtype_like import DTypeLike, _DTypeLike from ._scalars import _ScalarLike_co from ._shape import _ShapeLike +### +# type parameters + _T = TypeVar("_T") -_2Tuple: TypeAlias = tuple[_T, _T] -_3Tuple: TypeAlias = tuple[_T, _T, _T] -_4Tuple: TypeAlias = tuple[_T, _T, _T, _T] - -_2PTuple: TypeAlias = tuple[_T, _T, Unpack[tuple[_T, ...]]] -_3PTuple: TypeAlias = tuple[_T, _T, _T, Unpack[tuple[_T, ...]]] -_4PTuple: TypeAlias = tuple[_T, _T, _T, _T, Unpack[tuple[_T, ...]]] - -_NTypesT_co = TypeVar("_NTypesT_co", bound=int, covariant=True) -_IdentityT_co = TypeVar("_IdentityT_co", default=None, covariant=True) -_NameT_co = TypeVar("_NameT_co", bound=LiteralString, covariant=True) -_SignatureT_co = TypeVar("_SignatureT_co", bound=LiteralString, covariant=True) -_OutT_co = TypeVar("_OutT_co", covariant=True) +_ArrayT = TypeVar("_ArrayT", bound=_AnyArray) +_ArrayT1 = TypeVar("_ArrayT1", bound=_AnyArray) +_ArrayT2 = TypeVar("_ArrayT2", bound=_AnyArray) +_ScalarT = TypeVar("_ScalarT", bound=np.generic) +_OutT = TypeVar("_OutT") +_OutT_co = TypeVar("_OutT_co", default=Any, covariant=True) +_OutT1 = TypeVar("_OutT1", default=Any) _OutT1_co = TypeVar("_OutT1_co", covariant=True) +_OutT2 = TypeVar("_OutT2", default=Any) _OutT2_co = TypeVar("_OutT2_co", covariant=True) -_ArrayT = TypeVar("_ArrayT", bound=npt.NDArray[Any]) -_ArrayT1 = TypeVar("_ArrayT1", bound=npt.NDArray[Any]) -_ArrayT2 = TypeVar("_ArrayT2", bound=npt.NDArray[Any]) + +### +# helper types + +_Tuple2: TypeAlias = tuple[_T, _T] +_Tuple3: TypeAlias = tuple[_T, _T, _T] +_Tuple4: TypeAlias = tuple[_T, _T, _T, _T] +_Tuple2_: TypeAlias = tuple[_T, _T, Unpack[tuple[_T, ...]]] +_Tuple3_: TypeAlias = tuple[_T, _T, _T, Unpack[tuple[_T, ...]]] +_Tuple4_: TypeAlias = tuple[_T, _T, _T, _T, Unpack[tuple[_T, ...]]] +_Out1: TypeAlias = _T | tuple[_T] +_AnyArray: TypeAlias = NDArray[Any] +_UFuncMethod: TypeAlias = L["__call__", "reduce", "reduceat", "accumulate", "outer", "at"] + +### +# helper protocols @type_check_only -class _SupportsArrayUFunc(Protocol): - def __array_ufunc__( - self, - ufunc: np.ufunc, - method: Literal["__call__", "reduce", "reduceat", "accumulate", "outer", "at"], - /, - *inputs: Any, - **kwargs: Any, - ) -> Any: ... +class _CanArrayUFunc(Protocol[_OutT_co]): + def __array_ufunc__(self, ufunc: np.ufunc, method: _UFuncMethod, /, *args: Any, **kwds: Any) -> _OutT_co: ... + +### +# typeddicts for kwargs @type_check_only -class _UFunc3Kwargs(TypedDict, total=False): - where: _ArrayLikeBool_co | None - casting: np._CastingKind - order: np._OrderKACF +class _KwargsCommon(TypedDict, total=False): + casting: _CastingKind + order: _OrderKACF subok: bool - signature: _3Tuple[str | None] | str | None -# NOTE: `reduce`, `accumulate`, `reduceat` and `outer` raise a ValueError for -# ufuncs that don't accept two input arguments and return one output argument. -# In such cases the respective methods return `NoReturn` +@type_check_only +class _Kwargs2(_KwargsCommon, total=False): + where: _ArrayLikeBool_co | None + signature: _Tuple2[DTypeLike] | str | None -# NOTE: Similarly, `at` won't be defined for ufuncs that return -# multiple outputs; in such cases `at` is typed to return `NoReturn` +@type_check_only +class _Kwargs3(_KwargsCommon, total=False): + where: _ArrayLikeBool_co | None + signature: _Tuple3[DTypeLike] | str | None -# NOTE: If 2 output types are returned then `out` must be a -# 2-tuple of arrays. Otherwise `None` or a plain array are also acceptable +@type_check_only +class _Kwargs3_g(_KwargsCommon, total=False): + signature: _Tuple3[DTypeLike] | str | None -# pyright: reportIncompatibleMethodOverride=false +@type_check_only +class _Kwargs4(_KwargsCommon, total=False): + where: _ArrayLikeBool_co | None + signature: _Tuple4[DTypeLike] | str | None @type_check_only -class _UFunc_Nin1_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def __name__(self) -> _NameT_co: ... - @property - def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] - @property - def ntypes(self) -> _NTypesT_co: ... - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> Literal[1]: ... - @property - def nout(self) -> Literal[1]: ... - @property - def nargs(self) -> Literal[2]: ... - @property - def signature(self) -> None: ... - @overload +class _Kwargs3_(_KwargsCommon, total=False): + where: _ArrayLikeBool_co | None + signature: _Tuple3_[DTypeLike] | str | None + +@type_check_only +class _Kwargs4_(_KwargsCommon, total=False): + where: _ArrayLikeBool_co | None + signature: _Tuple4_[DTypeLike] | str | None + +### +# ufunc method signatures + +@type_check_only +class _Call11(Protocol): + @overload # (scalar, dtype: dtype[T]) -> T def __call__( self, x1: _ScalarLike_co, /, out: None = None, *, - where: _ArrayLikeBool_co | None = ..., - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _2Tuple[str | None] = ..., - ) -> Any: ... - @overload + dtype: _DTypeLike[_ScalarT], + **kwds: Unpack[_Kwargs2], + ) -> _ScalarT: ... + @overload # (scalar) -> ? def __call__( self, - x1: ArrayLike, + x1: _ScalarLike_co, /, - out: npt.NDArray[Any] | tuple[npt.NDArray[Any]] | None = ..., + out: None = None, *, - where: _ArrayLikeBool_co | None = ..., - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _2Tuple[str | None] = ..., - ) -> npt.NDArray[Any]: ... - @overload + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs2], + ) -> Any: ... + @overload # (array, dtype: dtype[T]) -> Array[T] def __call__( self, - x1: _SupportsArrayUFunc, + x1: _AnyArray, /, - out: npt.NDArray[Any] | tuple[npt.NDArray[Any]] | None = ..., + out: _Out1[_AnyArray] | None = None, *, - where: _ArrayLikeBool_co | None = ..., - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _2Tuple[str | None] = ..., - ) -> Any: ... - def at(self, a: _SupportsArrayUFunc, indices: _ArrayLikeInt_co, /) -> None: ... - def reduce(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def accumulate(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduceat(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def outer(self, *args: Any, **kwargs: Any) -> NoReturn: ... - -@type_check_only -class _UFunc_Nin2_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def __name__(self) -> _NameT_co: ... - @property - def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] - @property - def ntypes(self) -> _NTypesT_co: ... - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> Literal[2]: ... - @property - def nout(self) -> Literal[1]: ... - @property - def nargs(self) -> Literal[3]: ... - @property - def signature(self) -> None: ... - @overload # (scalar, scalar) -> scalar + dtype: _DTypeLike[_ScalarT], + **kwds: Unpack[_Kwargs2], + ) -> NDArray[_ScalarT]: ... + @overload # (array-like, out: T) -> T def __call__( self, - x1: _ScalarLike_co, - x2: _ScalarLike_co, + x1: ArrayLike, /, - out: None = None, + out: _Out1[_ArrayT], *, dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> Any: ... - @overload # (array-like, array) -> array + **kwds: Unpack[_Kwargs2], + ) -> _ArrayT: ... + @overload # (array) -> Array[?] | ? def __call__( self, - x1: ArrayLike, - x2: npt.NDArray[np.generic], + x1: _AnyArray, /, - out: npt.NDArray[np.generic] | tuple[npt.NDArray[np.generic]] | None = None, + out: _Out1[_AnyArray] | None = None, *, dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> npt.NDArray[Any]: ... - @overload # (array, array-like) -> array + **kwds: Unpack[_Kwargs2], + ) -> _AnyArray: ... + @overload # (array-like) -> Array[?] | ? def __call__( self, - x1: npt.NDArray[np.generic], - x2: ArrayLike, + x1: ArrayLike, /, - out: npt.NDArray[np.generic] | tuple[npt.NDArray[np.generic]] | None = None, + out: _Out1[_AnyArray] | None = None, *, dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> npt.NDArray[Any]: ... - @overload # (array-like, array-like, out=array) -> array + **kwds: Unpack[_Kwargs2], + ) -> _AnyArray | Any: ... + @overload # (?) -> ? def __call__( self, - x1: ArrayLike, - x2: ArrayLike, + x1: _CanArrayUFunc, /, - out: npt.NDArray[np.generic] | tuple[npt.NDArray[np.generic]], + out: _Out1[_AnyArray] | None = None, *, dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> npt.NDArray[Any]: ... - @overload # (array-like, array-like) -> array | scalar + **kwds: Unpack[_Kwargs2], + ) -> Any: ... + +@type_check_only +class _Call12(Protocol): + @overload def __call__( self, - x1: ArrayLike, - x2: ArrayLike, + x: _ScalarLike_co, + out1: None = None, + out2: None = None, /, - out: npt.NDArray[np.generic] | tuple[npt.NDArray[np.generic]] | None = None, *, + out: _Tuple2[None] = (None, None), dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> npt.NDArray[Any] | Any: ... - def at(self, a: npt.NDArray[Any], indices: _ArrayLikeInt_co, b: ArrayLike, /) -> None: ... - def reduce( + **kwds: Unpack[_Kwargs3], + ) -> _Tuple2[Any]: ... + @overload + def __call__( self, - array: ArrayLike, - axis: _ShapeLike | None = ..., - dtype: DTypeLike = ..., - out: npt.NDArray[Any] | None = ..., - keepdims: bool = ..., - initial: Any = ..., - where: _ArrayLikeBool_co = ..., - ) -> Any: ... - def accumulate( + x: ArrayLike, + out1: None, + out2: _ArrayT2, + /, + *, + out: tuple[None, None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs3], + ) -> tuple[None, _ArrayT2]: ... + @overload + def __call__( self, - array: ArrayLike, - axis: SupportsIndex = ..., - dtype: DTypeLike = ..., - out: npt.NDArray[Any] | None = ..., - ) -> npt.NDArray[Any]: ... - def reduceat( + x: ArrayLike, + out1: _ArrayT1, + out2: None = None, + /, + *, + out: tuple[None, None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs3], + ) -> tuple[_ArrayT1, None]: ... + @overload + def __call__( self, - array: ArrayLike, - indices: _ArrayLikeInt_co, - axis: SupportsIndex = ..., - dtype: DTypeLike = ..., - out: npt.NDArray[Any] | None = ..., - ) -> npt.NDArray[Any]: ... - @overload # (scalar, scalar) -> scalar - def outer( + x: ArrayLike, + out1: _ArrayT1, + out2: _ArrayT2, + /, + *, + out: tuple[None, None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs3], + ) -> tuple[_ArrayT1, _ArrayT2]: ... + @overload + def __call__( self, - A: _ScalarLike_co, - B: _ScalarLike_co, + x: ArrayLike, + out1: None = None, + out2: None = None, /, *, - out: None = None, - dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> Any: ... - @overload # (array-like, array) -> array - def outer( + out: tuple[None, _ArrayT2], + dtype: None = None, + **kwds: Unpack[_Kwargs3], + ) -> tuple[_AnyArray, _ArrayT2]: ... + @overload + def __call__( self, - A: ArrayLike, - B: npt.NDArray[np.generic], + x: ArrayLike, + out1: None = None, + out2: None = None, /, *, - out: npt.NDArray[np.generic] | tuple[npt.NDArray[np.generic]] | None = None, - dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> npt.NDArray[Any]: ... - @overload # (array, array-like) -> array - def outer( + out: tuple[_ArrayT1, None], + dtype: None = None, + **kwds: Unpack[_Kwargs3], + ) -> tuple[_ArrayT1, _AnyArray]: ... + @overload + def __call__( self, - A: npt.NDArray[np.generic], - B: ArrayLike, + x: ArrayLike, + out1: None = None, + out2: None = None, /, *, - out: npt.NDArray[np.generic] | tuple[npt.NDArray[np.generic]] | None = None, - dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> npt.NDArray[Any]: ... - @overload # (array-like, array-like, out=array) -> array - def outer( + out: tuple[_ArrayT1, _ArrayT2], + dtype: None = None, + **kwds: Unpack[_Kwargs3], + ) -> tuple[_ArrayT1, _ArrayT2]: ... + @overload + def __call__( self, - A: ArrayLike, - B: ArrayLike, + x: _AnyArray, + out1: _AnyArray | None = None, + out2: _AnyArray | None = None, /, *, - out: npt.NDArray[np.generic] | tuple[npt.NDArray[np.generic]], + out: _Tuple2[_AnyArray | None] = (None, None), dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> npt.NDArray[Any]: ... - @overload # (array-like, array-like) -> array | scalar - def outer( + **kwds: Unpack[_Kwargs3], + ) -> _Tuple2[_AnyArray]: ... + @overload + def __call__( self, - A: ArrayLike, - B: ArrayLike, + x: _CanArrayUFunc, + out1: _AnyArray | None = None, + out2: _AnyArray | None = None, /, *, - out: npt.NDArray[np.generic] | tuple[npt.NDArray[np.generic]] | None = None, + out: _Tuple2[_AnyArray | None] = (None, None), dtype: DTypeLike | None = None, - **kwds: Unpack[_UFunc3Kwargs], - ) -> npt.NDArray[Any] | Any: ... + **kwds: Unpack[_Kwargs3], + ) -> _Tuple2[Any]: ... @type_check_only -class _UFunc_Nin1_Nout2(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def __name__(self) -> _NameT_co: ... - @property - def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] - @property - def ntypes(self) -> _NTypesT_co: ... - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> Literal[1]: ... - @property - def nout(self) -> Literal[2]: ... - @property - def nargs(self) -> Literal[3]: ... - @property - def signature(self) -> None: ... - @overload +class _Call21(Protocol): + @overload # (scalar, scalar, dtype: type[T]) -> T def __call__( self, x1: _ScalarLike_co, - out1: None = ..., - out2: None = ..., + x2: _ScalarLike_co, /, + out: None = None, *, - where: _ArrayLikeBool_co | None = ..., - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _3Tuple[str | None] = ..., - ) -> _2Tuple[Any]: ... - @overload + dtype: _DTypeLike[_ScalarT], + **kwds: Unpack[_Kwargs3], + ) -> _ScalarT: ... + @overload # (scalar, scalar) -> ? def __call__( self, - x1: ArrayLike, - out1: npt.NDArray[Any] | None = ..., - out2: npt.NDArray[Any] | None = ..., + x1: _ScalarLike_co, + x2: _ScalarLike_co, /, + out: None = None, *, - out: _2Tuple[npt.NDArray[Any]] = ..., - where: _ArrayLikeBool_co | None = ..., - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _3Tuple[str | None] = ..., - ) -> _2Tuple[npt.NDArray[Any]]: ... - @overload + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3], + ) -> Any: ... + @overload # (array-like, array, dtype: dtype[T]) -> Array[T] def __call__( self, - x1: _SupportsArrayUFunc, - out1: npt.NDArray[Any] | None = ..., - out2: npt.NDArray[Any] | None = ..., + x1: ArrayLike, + x2: _AnyArray, /, + out: None = None, *, - out: _2Tuple[npt.NDArray[Any]] = ..., - where: _ArrayLikeBool_co | None = ..., - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _3Tuple[str | None] = ..., - ) -> _2Tuple[Any]: ... - def at(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduce(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def accumulate(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduceat(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def outer(self, *args: Any, **kwargs: Any) -> NoReturn: ... - -@type_check_only -class _UFunc_Nin2_Nout2(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def __name__(self) -> _NameT_co: ... - @property - def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] - @property - def ntypes(self) -> _NTypesT_co: ... - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> Literal[2]: ... - @property - def nout(self) -> Literal[2]: ... - @property - def nargs(self) -> Literal[4]: ... - @property - def signature(self) -> None: ... - @overload + dtype: _DTypeLike[_ScalarT], + **kwds: Unpack[_Kwargs3], + ) -> NDArray[_ScalarT]: ... + @overload # (array, array-like, dtype: dtype[T]) -> Array[T] def __call__( self, - x1: _ScalarLike_co, - x2: _ScalarLike_co, - out1: None = ..., - out2: None = ..., + x1: _AnyArray, + x2: ArrayLike, /, + out: None = None, *, - where: _ArrayLikeBool_co | None = ..., - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _4Tuple[str | None] = ..., - ) -> _2Tuple[Any]: ... - @overload + dtype: _DTypeLike[_ScalarT], + **kwds: Unpack[_Kwargs3], + ) -> NDArray[_ScalarT]: ... + @overload # (array-like, array) -> Array[?] def __call__( self, x1: ArrayLike, + x2: _AnyArray, + /, + out: _Out1[_AnyArray] | None = None, + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3], + ) -> _AnyArray: ... + @overload # (array, array-like) -> Array[?] + def __call__( + self, + x1: _AnyArray, x2: ArrayLike, - out1: npt.NDArray[Any] | None = ..., - out2: npt.NDArray[Any] | None = ..., - /, - *, - out: _2Tuple[npt.NDArray[Any]] = ..., - where: _ArrayLikeBool_co | None = ..., - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _4Tuple[str | None] = ..., - ) -> _2Tuple[npt.NDArray[Any]]: ... - def at(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduce(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def accumulate(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduceat(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def outer(self, *args: Any, **kwargs: Any) -> NoReturn: ... - -@type_check_only -class _GUFunc_Nin2_Nout1(np.ufunc, Generic[_NameT_co, _NTypesT_co, _IdentityT_co, _SignatureT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def __name__(self) -> _NameT_co: ... - @property - def __qualname__(self) -> _NameT_co: ... # pyright: ignore[reportIncompatibleVariableOverride] - @property - def ntypes(self) -> _NTypesT_co: ... - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> Literal[2]: ... - @property - def nout(self) -> Literal[1]: ... - @property - def nargs(self) -> Literal[3]: ... - @property - def signature(self) -> _SignatureT_co: ... - - # Scalar for 1D array-likes; ndarray otherwise - @overload + /, + out: _Out1[_AnyArray] | None = None, + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3], + ) -> _AnyArray: ... + @overload # (array-like, array-like, out: T) -> T def __call__( self, x1: ArrayLike, x2: ArrayLike, /, - out: None = None, + out: _ArrayT | tuple[_ArrayT], *, - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _3Tuple[str | None] = ..., - axes: list[_2Tuple[SupportsIndex]] = ..., - ) -> Any: ... - @overload + dtype: None = None, + **kwds: Unpack[_Kwargs3], + ) -> _ArrayT: ... + @overload # (array-like, array-like) -> Array[?] | ? def __call__( self, x1: ArrayLike, x2: ArrayLike, /, - out: npt.NDArray[Any] | tuple[npt.NDArray[Any]], - *, - casting: np._CastingKind = ..., - order: np._OrderKACF = ..., - dtype: DTypeLike = ..., - subok: bool = ..., - signature: str | _3Tuple[str | None] = ..., - axes: list[_2Tuple[SupportsIndex]] = ..., - ) -> npt.NDArray[Any]: ... - def at(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduce(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def accumulate(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduceat(self, *args: Any, **kwargs: Any) -> NoReturn: ... - def outer(self, *args: Any, **kwargs: Any) -> NoReturn: ... - -@type_check_only -class _PyFunc_Kwargs_Nargs2(TypedDict, total=False): - where: _ArrayLikeBool_co | None - casting: np._CastingKind - order: np._OrderKACF - dtype: DTypeLike - subok: bool - signature: str | tuple[DTypeLike, DTypeLike] - -@type_check_only -class _PyFunc_Kwargs_Nargs3(TypedDict, total=False): - where: _ArrayLikeBool_co | None - casting: np._CastingKind - order: np._OrderKACF - dtype: DTypeLike - subok: bool - signature: str | tuple[DTypeLike, DTypeLike, DTypeLike] - -@type_check_only -class _PyFunc_Kwargs_Nargs3P(TypedDict, total=False): - where: _ArrayLikeBool_co | None - casting: np._CastingKind - order: np._OrderKACF - dtype: DTypeLike - subok: bool - signature: str | _3PTuple[DTypeLike] - -@type_check_only -class _PyFunc_Kwargs_Nargs4P(TypedDict, total=False): - where: _ArrayLikeBool_co | None - casting: np._CastingKind - order: np._OrderKACF - dtype: DTypeLike - subok: bool - signature: str | _4PTuple[DTypeLike] + out: _Out1[_AnyArray] | None = None, + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3], + ) -> _AnyArray | Any: ... @type_check_only -class _PyFunc_Nin1_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> Literal[1]: ... - @property - def nout(self) -> Literal[1]: ... - @property - def nargs(self) -> Literal[2]: ... - @property - def ntypes(self) -> Literal[1]: ... - @property - def signature(self) -> None: ... +class _Call22(Protocol): @overload def __call__( self, x1: _ScalarLike_co, + x2: _ScalarLike_co, + out1: None = None, + out2: None = None, /, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs2], - ) -> _OutT_co: ... + *, + out: _Tuple2[None] = (None, None), + dtype: _DTypeLike[_ScalarT], + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[_ScalarT]: ... @overload def __call__( self, - x1: ArrayLike, + x1: _ScalarLike_co, + x2: _ScalarLike_co, + out1: None = None, + out2: None = None, /, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs2], - ) -> _OutT_co | npt.NDArray[np.object_]: ... + *, + out: _Tuple2[None] = (None, None), + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[Any]: ... @overload def __call__( self, - x1: ArrayLike, + x1: _AnyArray, + x2: ArrayLike, + out1: NDArray[_ScalarT] | None = None, + out2: NDArray[_ScalarT] | None = None, /, - out: _ArrayT | tuple[_ArrayT], - **kwargs: Unpack[_PyFunc_Kwargs_Nargs2], - ) -> _ArrayT: ... + *, + out: _Tuple2[NDArray[_ScalarT] | None] = (None, None), + dtype: _DTypeLike[_ScalarT], + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[NDArray[_ScalarT]]: ... @overload def __call__( self, - x1: _SupportsArrayUFunc, + x1: ArrayLike, + x2: _AnyArray, + out1: NDArray[_ScalarT] | None = None, + out2: NDArray[_ScalarT] | None = None, /, - out: npt.NDArray[Any] | tuple[npt.NDArray[Any]] | None = ..., - **kwargs: Unpack[_PyFunc_Kwargs_Nargs2], - ) -> Any: ... - def at(self, a: _SupportsArrayUFunc, ixs: _ArrayLikeInt_co, /) -> None: ... - def reduce(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def accumulate(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduceat(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def outer(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - -@type_check_only -class _PyFunc_Nin2_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> Literal[2]: ... - @property - def nout(self) -> Literal[1]: ... - @property - def nargs(self) -> Literal[3]: ... - @property - def ntypes(self) -> Literal[1]: ... - @property - def signature(self) -> None: ... + *, + out: _Tuple2[NDArray[_ScalarT] | None] = (None, None), + dtype: _DTypeLike[_ScalarT], + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[NDArray[_ScalarT]]: ... @overload def __call__( self, - x1: _ScalarLike_co, - x2: _ScalarLike_co, + x1: _AnyArray, + x2: ArrayLike, + out1: _AnyArray | None = None, + out2: _AnyArray | None = None, /, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], - ) -> _OutT_co: ... + *, + out: _Tuple2[_AnyArray | None] = (None, None), + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[_AnyArray]: ... @overload def __call__( self, x1: ArrayLike, - x2: ArrayLike, + x2: _AnyArray, + out1: _AnyArray | None = None, + out2: _AnyArray | None = None, /, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], - ) -> _OutT_co | npt.NDArray[np.object_]: ... + *, + out: _Tuple2[_AnyArray | None] = (None, None), + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[_AnyArray]: ... @overload def __call__( self, x1: ArrayLike, x2: ArrayLike, + out1: _ArrayT1, + out2: None = None, /, - out: _ArrayT | tuple[_ArrayT], - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], - ) -> _ArrayT: ... + *, + out: _Tuple2[None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs4], + ) -> tuple[_ArrayT1, Any]: ... @overload def __call__( self, - x1: _SupportsArrayUFunc, - x2: _SupportsArrayUFunc | ArrayLike, + x1: ArrayLike, + x2: ArrayLike, + out1: None, + out2: _ArrayT2, /, - out: npt.NDArray[Any] | tuple[npt.NDArray[Any]] | None = ..., - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], - ) -> Any: ... + *, + out: _Tuple2[None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs4], + ) -> tuple[Any, _ArrayT2]: ... @overload def __call__( self, x1: ArrayLike, - x2: _SupportsArrayUFunc, + x2: ArrayLike, + out1: _ArrayT1, + out2: _ArrayT2, /, - out: npt.NDArray[Any] | tuple[npt.NDArray[Any]] | None = ..., - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], - ) -> Any: ... - def at(self, a: _SupportsArrayUFunc, ixs: _ArrayLikeInt_co, b: ArrayLike, /) -> None: ... + *, + out: _Tuple2[None] = (None, None), + dtype: None = None, + **kwds: Unpack[_Kwargs4], + ) -> tuple[_ArrayT1, _ArrayT2]: ... @overload - def reduce( + def __call__( self, - array: ArrayLike, - axis: _ShapeLike | None, - dtype: DTypeLike, - out: _ArrayT, + x1: ArrayLike, + x2: ArrayLike, + out1: None = None, + out2: None = None, /, - keepdims: bool = ..., - initial: _ScalarLike_co = ..., - where: _ArrayLikeBool_co = ..., - ) -> _ArrayT: ... + *, + out: tuple[_ArrayT1, None], + dtype: None = None, + **kwds: Unpack[_Kwargs4], + ) -> tuple[_ArrayT1, Any]: ... @overload - def reduce( + def __call__( self, + x1: ArrayLike, + x2: ArrayLike, + out1: None = None, + out2: None = None, /, - array: ArrayLike, - axis: _ShapeLike | None = ..., - dtype: DTypeLike = ..., *, - out: _ArrayT | tuple[_ArrayT], - keepdims: bool = ..., - initial: _ScalarLike_co = ..., - where: _ArrayLikeBool_co = ..., - ) -> _ArrayT: ... + out: tuple[None, _ArrayT2], + dtype: None = None, + **kwds: Unpack[_Kwargs4], + ) -> tuple[Any, _ArrayT2]: ... @overload - def reduce( + def __call__( self, + x1: ArrayLike, + x2: ArrayLike, + out1: None = None, + out2: None = None, /, - array: ArrayLike, - axis: _ShapeLike | None = ..., - dtype: DTypeLike = ..., - out: None = None, *, - keepdims: Literal[True], - initial: _ScalarLike_co = ..., - where: _ArrayLikeBool_co = ..., - ) -> npt.NDArray[np.object_]: ... + out: tuple[_ArrayT1, _ArrayT2], + dtype: None = None, + **kwds: Unpack[_Kwargs4], + ) -> tuple[_ArrayT1, _ArrayT2]: ... @overload - def reduce( + def __call__( self, + x1: ArrayLike | _CanArrayUFunc, + x2: ArrayLike | _CanArrayUFunc, + out1: _AnyArray | None = None, + out2: _AnyArray | None = None, /, - array: ArrayLike, - axis: _ShapeLike | None = ..., - dtype: DTypeLike = ..., - out: None = None, - keepdims: bool = ..., - initial: _ScalarLike_co = ..., - where: _ArrayLikeBool_co = ..., - ) -> _OutT_co | npt.NDArray[np.object_]: ... + *, + out: _Tuple2[_AnyArray | None] = (None, None), + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[Any]: ... + +@type_check_only +class _Call21_g(Protocol): + # Scalar for 1D array-likes; ndarray otherwise @overload - def reduceat( + def __call__( self, - array: ArrayLike, - indices: _ArrayLikeInt_co, - axis: SupportsIndex, - dtype: DTypeLike, - out: _ArrayT, + x1: ArrayLike, + x2: ArrayLike, /, + out: _Out1[_ArrayT], + *, + dtype: None = None, + axis: SupportsIndex = ..., + axes: Sequence[_Tuple2[SupportsIndex]] = ..., + **kwds: Unpack[_Kwargs3_g], ) -> _ArrayT: ... @overload - def reduceat( + def __call__( self, + x1: ArrayLike, + x2: ArrayLike, /, - array: ArrayLike, - indices: _ArrayLikeInt_co, - axis: SupportsIndex = ..., - dtype: DTypeLike = ..., + out: _Out1[_AnyArray | None] = None, *, - out: _ArrayT | tuple[_ArrayT], - ) -> _ArrayT: ... + dtype: DTypeLike | None = None, + axis: SupportsIndex = ..., + axes: Sequence[_Tuple2[SupportsIndex]] = ..., + **kwds: Unpack[_Kwargs3_g], + ) -> Any: ... + +@type_check_only +class _Call11_py(Protocol[_OutT_co]): @overload - def reduceat( + def __call__( self, + x: _ScalarLike_co, /, - array: ArrayLike, - indices: _ArrayLikeInt_co, - axis: SupportsIndex = ..., - dtype: DTypeLike = ..., out: None = None, - ) -> npt.NDArray[np.object_]: ... + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs2], + ) -> _OutT_co: ... @overload - def reduceat( + def __call__( self, + x: ArrayLike, /, - array: _SupportsArrayUFunc, - indices: _ArrayLikeInt_co, - axis: SupportsIndex = ..., - dtype: DTypeLike = ..., - out: npt.NDArray[Any] | tuple[npt.NDArray[Any]] | None = ..., - ) -> Any: ... + out: None = None, + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs2], + ) -> _OutT_co | NDArray[np.object_]: ... @overload - def accumulate( + def __call__( self, - array: ArrayLike, - axis: SupportsIndex, - dtype: DTypeLike, - out: _ArrayT, + x: ArrayLike, /, - ) -> _ArrayT: ... - @overload - def accumulate( - self, - array: ArrayLike, - axis: SupportsIndex = ..., - dtype: DTypeLike = ..., - *, out: _ArrayT | tuple[_ArrayT], + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs2], ) -> _ArrayT: ... @overload - def accumulate( + def __call__( self, + x: _CanArrayUFunc, /, - array: ArrayLike, - axis: SupportsIndex = ..., - dtype: DTypeLike = ..., - out: None = None, - ) -> npt.NDArray[np.object_]: ... + out: _Out1[_AnyArray] | None = None, + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs2], + ) -> Any: ... + +@type_check_only +class _Call21_py(Protocol[_OutT_co]): @overload - def outer( + def __call__( self, - A: _ScalarLike_co, - B: _ScalarLike_co, + x1: _ScalarLike_co, + x2: _ScalarLike_co, /, - *, out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3], ) -> _OutT_co: ... @overload - def outer( + def __call__( self, - A: ArrayLike, - B: ArrayLike, + x1: ArrayLike, + x2: ArrayLike, /, - *, out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], - ) -> _OutT_co | npt.NDArray[np.object_]: ... + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3], + ) -> _OutT_co | NDArray[np.object_]: ... @overload - def outer( + def __call__( self, - A: ArrayLike, - B: ArrayLike, + x1: ArrayLike, + x2: ArrayLike, /, - *, - out: _ArrayT, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + out: _ArrayT | tuple[_ArrayT], + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3], ) -> _ArrayT: ... @overload - def outer( + def __call__( self, - A: _SupportsArrayUFunc, - B: _SupportsArrayUFunc | ArrayLike, + x1: _CanArrayUFunc, + x2: _CanArrayUFunc | ArrayLike, /, - *, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + out: _Out1[_AnyArray] | None = None, + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3], ) -> Any: ... @overload - def outer( + def __call__( self, - A: _ScalarLike_co, - B: _SupportsArrayUFunc | ArrayLike, + x1: ArrayLike, + x2: _CanArrayUFunc, /, - *, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + out: _Out1[_AnyArray] | None = None, + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3], ) -> Any: ... @type_check_only -class _PyFunc_Nin3P_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> int: ... - @property - def nout(self) -> Literal[1]: ... - @property - def ntypes(self) -> Literal[1]: ... - @property - def signature(self) -> None: ... +class _Call3n1_py(Protocol[_OutT_co]): @overload def __call__( self, @@ -814,7 +676,8 @@ class _PyFunc_Nin3P_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: /, *xs: _ScalarLike_co, out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P], + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs4_], ) -> _OutT_co: ... @overload def __call__( @@ -825,8 +688,9 @@ class _PyFunc_Nin3P_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: /, *xs: ArrayLike, out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P], - ) -> _OutT_co | npt.NDArray[np.object_]: ... + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs4_], + ) -> _OutT_co | NDArray[np.object_]: ... @overload def __call__( self, @@ -836,45 +700,33 @@ class _PyFunc_Nin3P_Nout1(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: /, *xs: ArrayLike, out: _ArrayT | tuple[_ArrayT], - **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P], + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs4_], ) -> _ArrayT: ... @overload def __call__( self, - x1: _SupportsArrayUFunc | ArrayLike, - x2: _SupportsArrayUFunc | ArrayLike, - x3: _SupportsArrayUFunc | ArrayLike, + x1: _CanArrayUFunc | ArrayLike, + x2: _CanArrayUFunc | ArrayLike, + x3: _CanArrayUFunc | ArrayLike, /, - *xs: _SupportsArrayUFunc | ArrayLike, - out: npt.NDArray[Any] | tuple[npt.NDArray[Any]] | None = ..., - **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P], + *xs: _CanArrayUFunc | ArrayLike, + out: _Out1[_AnyArray] | None = None, + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs4_], ) -> Any: ... - def at(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduce(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def accumulate(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduceat(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def outer(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... @type_check_only -class _PyFunc_Nin1P_Nout2(np.ufunc, Generic[_OutT1_co, _OutT2_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> int: ... - @property - def nout(self) -> Literal[2]: ... - @property - def ntypes(self) -> Literal[1]: ... - @property - def signature(self) -> None: ... +class _Call1n2_py(Protocol[_OutT1_co, _OutT2_co]): @overload def __call__( self, x1: _ScalarLike_co, /, *xs: _ScalarLike_co, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], + out: tuple[None, None] = (None, None), + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3_], ) -> tuple[_OutT1_co, _OutT2_co]: ... @overload def __call__( @@ -882,9 +734,10 @@ class _PyFunc_Nin1P_Nout2(np.ufunc, Generic[_OutT1_co, _OutT2_co, _IdentityT_co] x1: ArrayLike, /, *xs: ArrayLike, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], - ) -> tuple[_OutT1_co | npt.NDArray[np.object_], _OutT2_co | npt.NDArray[np.object_]]: ... + out: tuple[None, None] = (None, None), + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3_], + ) -> tuple[_OutT1_co | NDArray[np.object_], _OutT2_co | NDArray[np.object_]]: ... @overload def __call__( self, @@ -892,73 +745,347 @@ class _PyFunc_Nin1P_Nout2(np.ufunc, Generic[_OutT1_co, _OutT2_co, _IdentityT_co] /, *xs: ArrayLike, out: tuple[_ArrayT1, _ArrayT2], - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3_], ) -> tuple[_ArrayT1, _ArrayT2]: ... @overload def __call__( self, - x1: _SupportsArrayUFunc | ArrayLike, + x1: _CanArrayUFunc | ArrayLike, /, - *xs: _SupportsArrayUFunc | ArrayLike, - out: _2PTuple[npt.NDArray[Any]] | None = ..., - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], + *xs: _CanArrayUFunc | ArrayLike, + out: _Tuple2[_AnyArray | None] = (None, None), + dtype: DTypeLike | None = None, + **kwds: Unpack[_Kwargs3_], ) -> Any: ... - def at(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduce(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def accumulate(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduceat(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def outer(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... @type_check_only -class _PyFunc_Nin1P_Nout2P(np.ufunc, Generic[_OutT_co, _IdentityT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] - @property - def identity(self) -> _IdentityT_co: ... - @property - def nin(self) -> int: ... - @property - def nout(self) -> int: ... - @property - def ntypes(self) -> Literal[1]: ... - @property - def signature(self) -> None: ... +class _Call1n2n_py(Protocol[_OutT_co]): @overload def __call__( self, x1: _ScalarLike_co, /, *xs: _ScalarLike_co, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], - ) -> _2PTuple[_OutT_co]: ... + out: _Tuple2_[None] = ..., + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3_], + ) -> _Tuple2_[_OutT_co]: ... @overload def __call__( self, x1: ArrayLike, /, *xs: ArrayLike, - out: None = None, - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], - ) -> _2PTuple[_OutT_co | npt.NDArray[np.object_]]: ... + out: _Tuple2_[None] = ..., + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3_], + ) -> _Tuple2_[_OutT_co | NDArray[np.object_]]: ... @overload def __call__( self, x1: ArrayLike, /, *xs: ArrayLike, - out: _2PTuple[_ArrayT], - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], - ) -> _2PTuple[_ArrayT]: ... + out: _Tuple2_[_ArrayT], + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3_], + ) -> _Tuple2_[_ArrayT]: ... @overload def __call__( self, - x1: _SupportsArrayUFunc | ArrayLike, + x1: _CanArrayUFunc | ArrayLike, + /, + *xs: _CanArrayUFunc | ArrayLike, + out: _Tuple2_[_AnyArray | None] = ..., + dtype: DTypeLike | None = None, + **kwargs: Unpack[_Kwargs3_], + ) -> Any: ... + +_AtE: TypeAlias = Callable[Concatenate[Never, Never, ...], None] +_At1: TypeAlias = Callable[[_CanArrayUFunc, _ArrayLikeInt_co], None] +_At2: TypeAlias = Callable[[_CanArrayUFunc, _ArrayLikeInt_co, ArrayLike], None] + +@type_check_only +class _ReduceE(Protocol): + def __call__( + self, + /, + array: Never, + axis: L[0] = 0, + dtype: None = None, + out: None = None, + keepdims: L[False] = False, + initial: Never = ..., + where: L[True] = True, + ) -> Any: ... + +@type_check_only +class _Reduce2(Protocol): + def __call__( + self, /, - *xs: _SupportsArrayUFunc | ArrayLike, - out: _2PTuple[npt.NDArray[Any]] | None = ..., - **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], + array: ArrayLike, + axis: _ShapeLike | None = 0, + dtype: DTypeLike | None = None, + out: _AnyArray | None = None, + keepdims: bool = False, + initial: _ScalarLike_co | None = ..., + where: _ArrayLikeBool_co = True, ) -> Any: ... - def at(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduce(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def accumulate(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def reduceat(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... - def outer(self, /, *args: Any, **kwargs: Any) -> NoReturn: ... + +@type_check_only +class _AccumulateE(Protocol): + def __call__(self, /, array: Never, axis: L[0] = 0, dtype: None = None, out: None = None) -> Any: ... + +@type_check_only +class _Accumulate2(Protocol): + @overload + def __call__(self, /, array: ArrayLike, axis: SupportsIndex, dtype: None, out: _ArrayT) -> _ArrayT: ... + @overload + def __call__(self, /, array: ArrayLike, axis: SupportsIndex = 0, dtype: None = None, *, out: _ArrayT) -> _ArrayT: ... + @overload + def __call__( + self, + /, + array: ArrayLike, + axis: SupportsIndex, + dtype: _DTypeLike[_ScalarT], + out: NDArray[_ScalarT] | None = None, + ) -> NDArray[_ScalarT]: ... + @overload + def __call__( + self, + /, + array: ArrayLike, + axis: SupportsIndex = 0, + *, + dtype: _DTypeLike[_ScalarT], + out: None = None, + ) -> NDArray[_ScalarT]: ... + @overload + def __call__( + self, + /, + array: ArrayLike, + axis: SupportsIndex = 0, + dtype: DTypeLike | None = None, + out: _AnyArray | None = None, + ) -> _AnyArray: ... + +@type_check_only +class _ReduceAtE(Protocol): + def __call__(self, /, array: Never, indices: Never, axis: L[0] = 0, dtype: None = None, out: None = None) -> Any: ... + +@type_check_only +class _ReduceAt2(Protocol): + @overload + def __call__( + self, + /, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex, + dtype: None, + out: _ArrayT, + ) -> _ArrayT: ... + @overload + def __call__( + self, + /, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex = 0, + dtype: None = None, + *, + out: _ArrayT, + ) -> _ArrayT: ... + @overload + def __call__( + self, + /, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex, + dtype: _DTypeLike[_ScalarT], + out: NDArray[_ScalarT] | None = None, + ) -> NDArray[_ScalarT]: ... + @overload + def __call__( + self, + /, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex = 0, + *, + dtype: _DTypeLike[_ScalarT], + out: NDArray[_ScalarT] | None = None, + ) -> NDArray[_ScalarT]: ... + @overload + def __call__( + self, + /, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex = 0, + dtype: DTypeLike | None = None, + out: _AnyArray | None = None, + ) -> _AnyArray: ... + +_OuterE: TypeAlias = Callable[[Never, Never], Any] + +@type_check_only +class _Outer1(Protocol): + @overload # (array-like, array-like, out: T) -> T + def __call__( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + dtype: None = None, + out: _Out1[_ArrayT], + **kwds: Unpack[_Kwargs3], + ) -> _ArrayT: ... + @overload # (array, array-like, dtype: dtype[T]) -> Array[T] + def __call__( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + dtype: _DTypeLike[_ScalarT], + out: _Out1[NDArray[_ScalarT]] | None = None, + **kwds: Unpack[_Kwargs3], + ) -> NDArray[_ScalarT]: ... + @overload # (array-like, array-like) -> array | scalar + def __call__( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + dtype: DTypeLike | None = None, + out: _Out1[_AnyArray] | None = None, + **kwds: Unpack[_Kwargs3], + ) -> _AnyArray: ... + +@type_check_only +class _Outer2(Protocol): + @overload # (array-like, array-like, out: (T1, None)) -> (T1, Array[?]) + def __call__( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + dtype: None = None, + out: tuple[_ArrayT1, None], + **kwds: Unpack[_Kwargs4], + ) -> tuple[_ArrayT1, _AnyArray]: ... + @overload # (array-like, array-like, out: (None, T2)) -> (Array[?], T2) + def __call__( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + dtype: None = None, + out: tuple[None, _ArrayT2], + **kwds: Unpack[_Kwargs4], + ) -> tuple[_AnyArray, _ArrayT2]: ... + @overload # (array-like, array-like, out: (T1, T2)) -> (T1, T2) + def __call__( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + dtype: None = None, + out: tuple[_ArrayT1, _ArrayT2], + **kwds: Unpack[_Kwargs4], + ) -> tuple[_ArrayT1, _ArrayT2]: ... + @overload # (array, array-like, dtype: dtype[T]) -> Array[T] + def __call__( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + dtype: _DTypeLike[_ScalarT], + out: _Tuple2[NDArray[_ScalarT] | None] = (None, None), + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[NDArray[_ScalarT]]: ... + @overload # (array-like, array-like) -> array | scalar + def __call__( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + dtype: DTypeLike | None = None, + out: _Tuple2[_AnyArray | None] = (None, None), + **kwds: Unpack[_Kwargs4], + ) -> _Tuple2[_AnyArray]: ... + +### +# specific ufunc aliases + +_CallT11 = TypeVar("_CallT11", bound=Callable[Concatenate[Any, ...], object], default=_Call11) +_CallT12 = TypeVar("_CallT12", bound=Callable[Concatenate[Any, ...], tuple[object, object]], default=_Call12) +_CallT21 = TypeVar("_CallT21", bound=Callable[Concatenate[Any, Any, ...], object], default=_Call21) +_CallT22 = TypeVar("_CallT22", bound=Callable[Concatenate[Any, Any, ...], tuple[object, object]], default=_Call22) +_CallT21G = TypeVar("_CallT21G", bound=Callable[Concatenate[Any, ...], object], default=_Call21_g) + +_ufunc_1_1 = TypeAliasType( + "_ufunc_1_1", + np.ufunc[_CallT11, _At1, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], + type_params=(_CallT11,), +) +_ufunc_1_2 = TypeAliasType( + "_ufunc_1_2", + np.ufunc[_CallT12, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], + type_params=(_CallT12,), +) +_ufunc_2_1 = TypeAliasType( + "_ufunc_2_1", + np.ufunc[_CallT21, _At2, _Reduce2, _ReduceAt2, _Accumulate2, _Outer1], + type_params=(_CallT21,), +) +_ufunc_2_2 = TypeAliasType( + "_ufunc_2_2", + np.ufunc[_CallT22, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _Outer2], + type_params=(_CallT22,), +) + +_gufunc_2_1 = TypeAliasType( + "_gufunc_2_1", + np.ufunc[_CallT21G, _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _Outer2], + type_params=(_CallT21G,), +) + +_pyfunc_1_1 = TypeAliasType( + "_pyfunc_1_1", + np.ufunc[_Call11_py[_OutT], _At1, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], + type_params=(_OutT,), +) +_pyfunc_2_1 = TypeAliasType( + "_pyfunc_2_1", + np.ufunc[_Call21_py[_OutT], _At2, _Reduce2, _ReduceAt2, _Accumulate2, _Outer1], + type_params=(_OutT,), +) +_pyfunc_3n_1 = TypeAliasType( + "_pyfunc_3n_1", + np.ufunc[_Call3n1_py[_OutT], _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], + type_params=(_OutT,), +) +_pyfunc_1n_2 = TypeAliasType( + "_pyfunc_1n_2", + np.ufunc[_Call1n2_py[_OutT1, _OutT2], _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], + type_params=(_OutT1, _OutT2), +) +_pyfunc_1n_2n = TypeAliasType( + "_pyfunc_1n_2n", + np.ufunc[_Call1n2n_py[_OutT], _AtE, _ReduceE, _ReduceAtE, _AccumulateE, _OuterE], + type_params=(_OutT,), +) diff --git a/src/numpy-stubs/matlib.pyi b/src/numpy-stubs/matlib.pyi index 9d2d26ad..3dd13ebe 100644 --- a/src/numpy-stubs/matlib.pyi +++ b/src/numpy-stubs/matlib.pyi @@ -70,6 +70,7 @@ from numpy import ( # noqa: ICN003 bitwise_invert, bitwise_left_shift, bitwise_not, + bitwise_or, bitwise_right_shift, bitwise_xor, blackman, diff --git a/test/static/accept/multiarray.pyi b/test/static/accept/multiarray.pyi index ce1be79f..ada534c7 100644 --- a/test/static/accept/multiarray.pyi +++ b/test/static/accept/multiarray.pyi @@ -1,5 +1,5 @@ import datetime as dt -from typing import Any, Literal as L +from typing import Any from typing_extensions import TypeVar, assert_type import numpy as np @@ -64,14 +64,8 @@ assert_type(b_i8_f8_f8.size, int) assert_type(np.inner(AR_f8, AR_i8), Any) -assert_type( - np.where([True, True, False], 1, 0), - npt.NDArray[Any], -) -assert_type( - np.where([True, True, False]), - tuple[npt.NDArray[np.intp], ...], -) +assert_type(np.where([True, True, False], 1, 0), npt.NDArray[Any]) +assert_type(np.where([True, True, False]), tuple[npt.NDArray[np.intp], ...]) assert_type(np.lexsort([0, 1, 2]), np.int_) @@ -115,79 +109,45 @@ assert_type(np.may_share_memory(AR_f8, AR_f8, max_work=1), bool) assert_type(np.promote_types(np.int32, np.int64), np.dtype[Any]) assert_type(np.promote_types("f4", float), np.dtype[Any]) -assert_type(np.frompyfunc(func11, 1, 1).nin, L[1]) -assert_type(np.frompyfunc(func11, 1, 1).nout, L[1]) -assert_type(np.frompyfunc(func11, 1, 1).nargs, L[2]) -assert_type(np.frompyfunc(func11, 1, 1).ntypes, L[1]) -assert_type(np.frompyfunc(func11, 1, 1).identity, None) -assert_type(np.frompyfunc(func11, 1, 1).signature, None) +assert_type(np.frompyfunc(func11, 1, 1).nin, int) +assert_type(np.frompyfunc(func11, 1, 1).nout, int) +assert_type(np.frompyfunc(func11, 1, 1).nargs, int) +assert_type(np.frompyfunc(func11, 1, 1).ntypes, int) +assert_type(np.frompyfunc(func11, 1, 1).identity, Any | None) +assert_type(np.frompyfunc(func11, 1, 1).signature, str | None) assert_type(np.frompyfunc(func11, 1, 1)(f8), bool) assert_type(np.frompyfunc(func11, 1, 1).at(AR_f8, AR_i8), None) -assert_type( - np.frompyfunc(func11, 1, 1)(AR_f8), - bool | npt.NDArray[np.object_], -) - -assert_type(np.frompyfunc(func21, 2, 1).nin, L[2]) -assert_type(np.frompyfunc(func21, 2, 1).nout, L[1]) -assert_type(np.frompyfunc(func21, 2, 1).nargs, L[3]) -assert_type(np.frompyfunc(func21, 2, 1).ntypes, L[1]) -assert_type(np.frompyfunc(func21, 2, 1).identity, None) -assert_type(np.frompyfunc(func21, 2, 1).signature, None) +assert_type(np.frompyfunc(func11, 1, 1)(AR_f8), bool | npt.NDArray[np.object_]) + +assert_type(np.frompyfunc(func21, 2, 1).nin, int) +assert_type(np.frompyfunc(func21, 2, 1).nout, int) +assert_type(np.frompyfunc(func21, 2, 1).nargs, int) +assert_type(np.frompyfunc(func21, 2, 1).ntypes, int) +assert_type(np.frompyfunc(func21, 2, 1).identity, Any | None) +assert_type(np.frompyfunc(func21, 2, 1).signature, str | None) assert_type(np.frompyfunc(func21, 2, 1)(f8, f8), int) -assert_type( - np.frompyfunc(func21, 2, 1)(AR_f8, f8), - int | npt.NDArray[np.object_], -) -assert_type( - np.frompyfunc(func21, 2, 1)(f8, AR_f8), - int | npt.NDArray[np.object_], -) -assert_type( - np.frompyfunc(func21, 2, 1).reduce(AR_f8, axis=0), - int | npt.NDArray[np.object_], -) -assert_type( - np.frompyfunc(func21, 2, 1).accumulate(AR_f8), - npt.NDArray[np.object_], -) -assert_type( - np.frompyfunc(func21, 2, 1).reduceat(AR_f8, AR_i8), - npt.NDArray[np.object_], -) -assert_type( - np.frompyfunc(func21, 2, 1).outer(f8, f8), - int, -) -assert_type( - np.frompyfunc(func21, 2, 1).outer(AR_f8, f8), - int | npt.NDArray[np.object_], -) - -assert_type(np.frompyfunc(func21, 2, 1, identity=0).nin, L[2]) -assert_type(np.frompyfunc(func21, 2, 1, identity=0).nout, L[1]) -assert_type(np.frompyfunc(func21, 2, 1, identity=0).nargs, L[3]) -assert_type(np.frompyfunc(func21, 2, 1, identity=0).ntypes, L[1]) -assert_type(np.frompyfunc(func21, 2, 1, identity=0).identity, int) -assert_type(np.frompyfunc(func21, 2, 1, identity=0).signature, None) +assert_type(np.frompyfunc(func21, 2, 1)(AR_f8, f8), int | npt.NDArray[np.object_]) +assert_type(np.frompyfunc(func21, 2, 1)(f8, AR_f8), int | npt.NDArray[np.object_]) +assert_type(np.frompyfunc(func21, 2, 1).reduce(AR_f8, axis=0), Any) +assert_type(np.frompyfunc(func21, 2, 1).accumulate(AR_f8), npt.NDArray[Any]) +assert_type(np.frompyfunc(func21, 2, 1).reduceat(AR_f8, AR_i8), npt.NDArray[Any]) +assert_type(np.frompyfunc(func21, 2, 1).outer(AR_f8, f8), npt.NDArray[Any]) + +assert_type(np.frompyfunc(func21, 2, 1, identity=0).nin, int) +assert_type(np.frompyfunc(func21, 2, 1, identity=0).nout, int) +assert_type(np.frompyfunc(func21, 2, 1, identity=0).nargs, int) +assert_type(np.frompyfunc(func21, 2, 1, identity=0).ntypes, int) +assert_type(np.frompyfunc(func21, 2, 1, identity=0).identity, Any | None) +assert_type(np.frompyfunc(func21, 2, 1, identity=0).signature, str | None) assert_type(np.frompyfunc(func12, 1, 2).nin, int) -assert_type(np.frompyfunc(func12, 1, 2).nout, L[2]) +assert_type(np.frompyfunc(func12, 1, 2).nout, int) assert_type(np.frompyfunc(func12, 1, 2).nargs, int) -assert_type(np.frompyfunc(func12, 1, 2).ntypes, L[1]) -assert_type(np.frompyfunc(func12, 1, 2).identity, None) -assert_type(np.frompyfunc(func12, 1, 2).signature, None) -assert_type( - np.frompyfunc(func12, 1, 2)(f8, f8), - tuple[complex, str], -) -assert_type( - np.frompyfunc(func12, 1, 2)(AR_f8, f8), - tuple[ - complex | npt.NDArray[np.object_], - str | npt.NDArray[np.object_], - ], -) +assert_type(np.frompyfunc(func12, 1, 2).ntypes, int) +assert_type(np.frompyfunc(func12, 1, 2).identity, Any | None) +assert_type(np.frompyfunc(func12, 1, 2).signature, str | None) +assert_type(np.frompyfunc(func12, 1, 2)(f8, f8), tuple[complex, str]) +assert_type(np.frompyfunc(func12, 1, 2)(AR_f8, f8), tuple[complex | npt.NDArray[np.object_], str | npt.NDArray[np.object_]]) assert_type(np.datetime_data("m8[D]"), tuple[str, int]) assert_type(np.datetime_data(np.datetime64), tuple[str, int]) @@ -201,22 +161,10 @@ assert_type(np.busday_offset(date_scalar, m), np.datetime64[dt.datetime]) assert_type(np.busday_offset(M, m), np.datetime64[dt.datetime]) assert_type(np.busday_offset(M, 5), np.datetime64[dt.datetime]) assert_type(np.busday_offset(AR_M, m), npt.NDArray[np.datetime64[dt.datetime]]) -assert_type( - np.busday_offset(M, timedelta_seq), - npt.NDArray[np.datetime64[dt.datetime]], -) -assert_type( - np.busday_offset("2011-01", 1, roll="forward"), - np.datetime64[dt.datetime], -) -assert_type( - np.busday_offset(["2011-01"], 1, roll="forward"), - npt.NDArray[np.datetime64[dt.datetime]], -) -assert_type( - np.busday_offset(["2011-01"], [1], roll="forward"), - npt.NDArray[np.datetime64[dt.datetime]], -) +assert_type(np.busday_offset(M, timedelta_seq), npt.NDArray[np.datetime64[dt.datetime]]) +assert_type(np.busday_offset("2011-01", 1, roll="forward"), np.datetime64[dt.datetime]) +assert_type(np.busday_offset(["2011-01"], 1, roll="forward"), npt.NDArray[np.datetime64[dt.datetime]]) +assert_type(np.busday_offset(["2011-01"], [1], roll="forward"), npt.NDArray[np.datetime64[dt.datetime]]) assert_type(np.is_busday("2012"), np.bool) assert_type(np.is_busday(date_scalar), np.bool) @@ -228,28 +176,10 @@ assert_type(np.datetime_as_string(AR_M), npt.NDArray[np.str_]) assert_type(np.busdaycalendar(holidays=date_seq), np.busdaycalendar) assert_type(np.busdaycalendar(holidays=[M]), np.busdaycalendar) -assert_type( - np.char.compare_chararrays("a", "b", "!=", rstrip=False), - npt.NDArray[np.bool], -) -assert_type( - np.char.compare_chararrays(b"a", b"a", "==", True), - npt.NDArray[np.bool], -) - -assert_type( - np.nested_iters([AR_i8, AR_i8], [[0], [1]], flags=["c_index"]), - tuple[np.nditer, ...], -) -assert_type( - np.nested_iters([AR_i8, AR_i8], [[0], [1]], op_flags=[["readonly", "readonly"]]), - tuple[np.nditer, ...], -) -assert_type( - np.nested_iters([AR_i8, AR_i8], [[0], [1]], op_dtypes=np.int_), - tuple[np.nditer, ...], -) -assert_type( - np.nested_iters([AR_i8, AR_i8], [[0], [1]], order="C", casting="no"), - tuple[np.nditer, ...], -) +assert_type(np.char.compare_chararrays("a", "b", "!=", rstrip=False), npt.NDArray[np.bool]) +assert_type(np.char.compare_chararrays(b"a", b"a", "==", True), npt.NDArray[np.bool]) + +assert_type(np.nested_iters([AR_i8, AR_i8], [[0], [1]], flags=["c_index"]), tuple[np.nditer, ...]) +assert_type(np.nested_iters([AR_i8, AR_i8], [[0], [1]], op_flags=[["readonly", "readonly"]]), tuple[np.nditer, ...]) +assert_type(np.nested_iters([AR_i8, AR_i8], [[0], [1]], op_dtypes=np.int_), tuple[np.nditer, ...]) +assert_type(np.nested_iters([AR_i8, AR_i8], [[0], [1]], order="C", casting="no"), tuple[np.nditer, ...]) diff --git a/test/static/accept/ufuncs.pyi b/test/static/accept/ufuncs.pyi index 82d8a5f7..af01606b 100644 --- a/test/static/accept/ufuncs.pyi +++ b/test/static/accept/ufuncs.pyi @@ -1,5 +1,5 @@ -from typing import Any, Literal, NoReturn -from typing_extensions import LiteralString, assert_type +from typing import Any +from typing_extensions import assert_type import numpy as np import numpy.typing as npt @@ -9,115 +9,30 @@ f8: np.float64 AR_f8: npt.NDArray[np.float64] AR_i8: npt.NDArray[np.int64] -assert_type(np.absolute.types, list[LiteralString]) +assert_type(np.absolute.types, list[str]) -assert_type(np.absolute.__name__, Literal["absolute"]) -assert_type(np.absolute.__qualname__, Literal["absolute"]) -assert_type(np.absolute.ntypes, Literal[20]) -assert_type(np.absolute.identity, None) -assert_type(np.absolute.nin, Literal[1]) -assert_type(np.absolute.nin, Literal[1]) -assert_type(np.absolute.nout, Literal[1]) -assert_type(np.absolute.nargs, Literal[2]) -assert_type(np.absolute.signature, None) assert_type(np.absolute(f8), Any) assert_type(np.absolute(AR_f8), npt.NDArray[Any]) assert_type(np.absolute.at(AR_f8, AR_i8), None) -assert_type(np.add.__name__, Literal["add"]) -assert_type(np.add.__qualname__, Literal["add"]) -assert_type(np.add.ntypes, Literal[22]) -assert_type(np.add.identity, Literal[0]) -assert_type(np.add.nin, Literal[2]) -assert_type(np.add.nout, Literal[1]) -assert_type(np.add.nargs, Literal[3]) -assert_type(np.add.signature, None) assert_type(np.add(f8, f8), Any) assert_type(np.add(AR_f8, f8), npt.NDArray[Any]) assert_type(np.add.at(AR_f8, AR_i8, f8), None) assert_type(np.add.reduce(AR_f8, axis=0), Any) assert_type(np.add.accumulate(AR_f8), npt.NDArray[Any]) assert_type(np.add.reduceat(AR_f8, AR_i8), npt.NDArray[Any]) -assert_type(np.add.outer(f8, f8), Any) assert_type(np.add.outer(AR_f8, f8), npt.NDArray[Any]) -assert_type(np.frexp.__name__, Literal["frexp"]) -assert_type(np.frexp.__qualname__, Literal["frexp"]) -assert_type(np.frexp.ntypes, Literal[4]) -assert_type(np.frexp.identity, None) -assert_type(np.frexp.nin, Literal[1]) -assert_type(np.frexp.nout, Literal[2]) -assert_type(np.frexp.nargs, Literal[3]) -assert_type(np.frexp.signature, None) assert_type(np.frexp(f8), tuple[Any, Any]) assert_type(np.frexp(AR_f8), tuple[npt.NDArray[Any], npt.NDArray[Any]]) -assert_type(np.divmod.__name__, Literal["divmod"]) -assert_type(np.divmod.__qualname__, Literal["divmod"]) -assert_type(np.divmod.ntypes, Literal[15]) -assert_type(np.divmod.identity, None) -assert_type(np.divmod.nin, Literal[2]) -assert_type(np.divmod.nout, Literal[2]) -assert_type(np.divmod.nargs, Literal[4]) -assert_type(np.divmod.signature, None) assert_type(np.divmod(f8, f8), tuple[Any, Any]) assert_type(np.divmod(AR_f8, f8), tuple[npt.NDArray[Any], npt.NDArray[Any]]) -assert_type(np.matmul.__name__, Literal["matmul"]) -assert_type(np.matmul.__qualname__, Literal["matmul"]) -assert_type(np.matmul.ntypes, Literal[19]) -assert_type(np.matmul.identity, None) -assert_type(np.matmul.nin, Literal[2]) -assert_type(np.matmul.nout, Literal[1]) -assert_type(np.matmul.nargs, Literal[3]) -assert_type(np.matmul.signature, Literal["(n?,k),(k,m?)->(n?,m?)"]) -assert_type(np.matmul.identity, None) assert_type(np.matmul(AR_f8, AR_f8), Any) assert_type(np.matmul(AR_f8, AR_f8, axes=[(0, 1), (0, 1), (0, 1)]), Any) -assert_type(np.vecdot.__name__, Literal["vecdot"]) -assert_type(np.vecdot.__qualname__, Literal["vecdot"]) -assert_type(np.vecdot.ntypes, Literal[19]) -assert_type(np.vecdot.identity, None) -assert_type(np.vecdot.nin, Literal[2]) -assert_type(np.vecdot.nout, Literal[1]) -assert_type(np.vecdot.nargs, Literal[3]) -assert_type(np.vecdot.signature, Literal["(n),(n)->()"]) -assert_type(np.vecdot.identity, None) assert_type(np.vecdot(AR_f8, AR_f8), Any) -assert_type(np.bitwise_count.__name__, Literal["bitwise_count"]) -assert_type(np.bitwise_count.__qualname__, Literal["bitwise_count"]) -assert_type(np.bitwise_count.ntypes, Literal[11]) -assert_type(np.bitwise_count.identity, None) -assert_type(np.bitwise_count.nin, Literal[1]) -assert_type(np.bitwise_count.nout, Literal[1]) -assert_type(np.bitwise_count.nargs, Literal[2]) -assert_type(np.bitwise_count.signature, None) -assert_type(np.bitwise_count.identity, None) assert_type(np.bitwise_count(i8), Any) assert_type(np.bitwise_count(AR_i8), npt.NDArray[Any]) - -assert_type(np.absolute.outer(), NoReturn) -assert_type(np.frexp.outer(), NoReturn) -assert_type(np.divmod.outer(), NoReturn) -assert_type(np.matmul.outer(), NoReturn) - -assert_type(np.absolute.reduceat(), NoReturn) -assert_type(np.frexp.reduceat(), NoReturn) -assert_type(np.divmod.reduceat(), NoReturn) -assert_type(np.matmul.reduceat(), NoReturn) - -assert_type(np.absolute.reduce(), NoReturn) -assert_type(np.frexp.reduce(), NoReturn) -assert_type(np.divmod.reduce(), NoReturn) -assert_type(np.matmul.reduce(), NoReturn) - -assert_type(np.absolute.accumulate(), NoReturn) -assert_type(np.frexp.accumulate(), NoReturn) -assert_type(np.divmod.accumulate(), NoReturn) -assert_type(np.matmul.accumulate(), NoReturn) - -assert_type(np.frexp.at(), NoReturn) -assert_type(np.divmod.at(), NoReturn) -assert_type(np.matmul.at(), NoReturn) diff --git a/test/static/reject/ufuncs.pyi b/test/static/reject/ufuncs.pyi index 3fd82235..70720956 100644 --- a/test/static/reject/ufuncs.pyi +++ b/test/static/reject/ufuncs.pyi @@ -16,3 +16,27 @@ np.matmul(AR_f8, AR_f8, where=True) # type: ignore[call-overload] # pyright: i np.frexp(AR_f8, out=None) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] np.frexp(AR_f8, out=AR_f8) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType] + +np.absolute.outer() # type: ignore[call-arg, misc] # pyright: ignore[reportCallIssue] +np.frexp.outer() # type: ignore[call-arg, misc] # pyright: ignore[reportCallIssue] +np.divmod.outer() # type: ignore[call-overload] # pyright: ignore[reportCallIssue] +np.matmul.outer() # type: ignore[call-overload] # pyright: ignore[reportCallIssue] + +np.absolute.reduceat() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.frexp.reduceat() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.divmod.reduceat() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.matmul.reduceat() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] + +np.absolute.reduce() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.frexp.reduce() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.divmod.reduce() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.matmul.reduce() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] + +np.absolute.accumulate() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.frexp.accumulate() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.divmod.accumulate() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] +np.matmul.accumulate() # type: ignore[call-arg] # pyright: ignore[reportCallIssue] + +np.frexp.at() # type: ignore[call-arg, misc] # pyright: ignore[reportCallIssue] +np.divmod.at() # type: ignore[call-arg, misc] # pyright: ignore[reportCallIssue] +np.matmul.at() # type: ignore[call-arg, misc] # pyright: ignore[reportCallIssue] From 2911ccd574af3f56dd63a249d4ae2af71f83db18 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 03:46:33 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=B4=20work=20around=20a=20mypy=20b?= =?UTF-8?q?ug=20with=20`Concatenate`=20and=20non-pos-only=20params?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/numpy-stubs/__init__.pyi | 7 +++--- src/numpy-stubs/_typing/_ufunc.pyi | 38 +++++++++++------------------- test/runtime/accept/ufuncs.py | 8 +++++++ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/numpy-stubs/__init__.pyi b/src/numpy-stubs/__init__.pyi index fc4d419e..e673c102 100644 --- a/src/numpy-stubs/__init__.pyi +++ b/src/numpy-stubs/__init__.pyi @@ -6637,13 +6637,13 @@ _ReduceT_co = TypeVar( _ReduceAtT_co = TypeVar( "_ReduceAtT_co", bound=Callable[Concatenate[Never, Never, ...], object], - default=Callable[Concatenate[Any, Any, ...], NDArray[Any]], + default=Callable[Concatenate[Any, Any, ...], ndarray[Any, dtype[Any]]], covariant=True, ) _AccumulateT_co = TypeVar( "_AccumulateT_co", bound=Callable[Concatenate[Never, ...], object], - default=Callable[Concatenate[Any, ...], NDArray[Any]], + default=Callable[Concatenate[Any, ...], ndarray[Any, dtype[Any]]], covariant=True, ) _OuterT_co = TypeVar( @@ -6696,7 +6696,8 @@ class ufunc(Generic[_CallT_co, _AtT_co, _ReduceT_co, _ReduceAtT_co, _AccumulateT reduction: py_bool = False, ) -> tuple[dtype[Any], ...]: ... -# TODO(jorenham): individually annotate each of the ufunc signatures +# TODO(jorenham): individual ufunc signature annotations +# https://github.com/numpy/numtype/issues/230 absolute: Final[_ufunc_1_1] = ... arccos: Final[_ufunc_1_1] = ... diff --git a/src/numpy-stubs/_typing/_ufunc.pyi b/src/numpy-stubs/_typing/_ufunc.pyi index 0fcadfdb..f037587c 100644 --- a/src/numpy-stubs/_typing/_ufunc.pyi +++ b/src/numpy-stubs/_typing/_ufunc.pyi @@ -808,24 +808,14 @@ _At2: TypeAlias = Callable[[_CanArrayUFunc, _ArrayLikeInt_co, ArrayLike], None] @type_check_only class _ReduceE(Protocol): - def __call__( - self, - /, - array: Never, - axis: L[0] = 0, - dtype: None = None, - out: None = None, - keepdims: L[False] = False, - initial: Never = ..., - where: L[True] = True, - ) -> Any: ... + def __call__(self, array: Never, /) -> Any: ... @type_check_only class _Reduce2(Protocol): def __call__( self, - /, array: ArrayLike, + /, axis: _ShapeLike | None = 0, dtype: DTypeLike | None = None, out: _AnyArray | None = None, @@ -836,19 +826,19 @@ class _Reduce2(Protocol): @type_check_only class _AccumulateE(Protocol): - def __call__(self, /, array: Never, axis: L[0] = 0, dtype: None = None, out: None = None) -> Any: ... + def __call__(self, array: Never, /) -> Any: ... @type_check_only class _Accumulate2(Protocol): @overload - def __call__(self, /, array: ArrayLike, axis: SupportsIndex, dtype: None, out: _ArrayT) -> _ArrayT: ... + def __call__(self, array: ArrayLike, /, axis: SupportsIndex, dtype: None, out: _ArrayT) -> _ArrayT: ... @overload - def __call__(self, /, array: ArrayLike, axis: SupportsIndex = 0, dtype: None = None, *, out: _ArrayT) -> _ArrayT: ... + def __call__(self, array: ArrayLike, /, axis: SupportsIndex = 0, dtype: None = None, *, out: _ArrayT) -> _ArrayT: ... @overload def __call__( self, - /, array: ArrayLike, + /, axis: SupportsIndex, dtype: _DTypeLike[_ScalarT], out: NDArray[_ScalarT] | None = None, @@ -856,8 +846,8 @@ class _Accumulate2(Protocol): @overload def __call__( self, - /, array: ArrayLike, + /, axis: SupportsIndex = 0, *, dtype: _DTypeLike[_ScalarT], @@ -866,8 +856,8 @@ class _Accumulate2(Protocol): @overload def __call__( self, - /, array: ArrayLike, + /, axis: SupportsIndex = 0, dtype: DTypeLike | None = None, out: _AnyArray | None = None, @@ -875,16 +865,16 @@ class _Accumulate2(Protocol): @type_check_only class _ReduceAtE(Protocol): - def __call__(self, /, array: Never, indices: Never, axis: L[0] = 0, dtype: None = None, out: None = None) -> Any: ... + def __call__(self, array: Never, indices: Never, /) -> Any: ... @type_check_only class _ReduceAt2(Protocol): @overload def __call__( self, - /, array: ArrayLike, indices: _ArrayLikeInt_co, + /, axis: SupportsIndex, dtype: None, out: _ArrayT, @@ -892,9 +882,9 @@ class _ReduceAt2(Protocol): @overload def __call__( self, - /, array: ArrayLike, indices: _ArrayLikeInt_co, + /, axis: SupportsIndex = 0, dtype: None = None, *, @@ -903,8 +893,8 @@ class _ReduceAt2(Protocol): @overload def __call__( self, - /, array: ArrayLike, + /, indices: _ArrayLikeInt_co, axis: SupportsIndex, dtype: _DTypeLike[_ScalarT], @@ -913,9 +903,9 @@ class _ReduceAt2(Protocol): @overload def __call__( self, - /, array: ArrayLike, indices: _ArrayLikeInt_co, + /, axis: SupportsIndex = 0, *, dtype: _DTypeLike[_ScalarT], @@ -924,9 +914,9 @@ class _ReduceAt2(Protocol): @overload def __call__( self, - /, array: ArrayLike, indices: _ArrayLikeInt_co, + /, axis: SupportsIndex = 0, dtype: DTypeLike | None = None, out: _AnyArray | None = None, diff --git a/test/runtime/accept/ufuncs.py b/test/runtime/accept/ufuncs.py index dbc61bb0..70ba546e 100644 --- a/test/runtime/accept/ufuncs.py +++ b/test/runtime/accept/ufuncs.py @@ -14,3 +14,11 @@ np.sin.__doc__ np.abs(np.array([1])) + + +u11: np.ufunc = np.log +u11_alias: np.ufunc = np.abs +u12: np.ufunc = np.modf +u21: np.ufunc = np.gcd +u22: np.ufunc = np.divmod +gu21: np.ufunc = np.matmul From e91330709a2414145e6e2902dc6ee8936fb2e86e Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 4 Mar 2025 04:24:30 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=90=B4=20ignore=20a=20false=20positiv?= =?UTF-8?q?e=20caused=20by=20the=20bundled=20`functools`=20mypy=20plugin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/runtime/accept/literal.py | 3 ++- test/runtime/accept/ufuncs.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/test/runtime/accept/literal.py b/test/runtime/accept/literal.py index db4bf607..5369d404 100644 --- a/test/runtime/accept/literal.py +++ b/test/runtime/accept/literal.py @@ -34,7 +34,8 @@ (KACF, partial(np.ones_like, AR)), (KACF, partial(np.empty_like, AR)), (KACF, partial(np.full_like, AR, 1)), - (KACF, partial(np.add.__call__, 1, 1)), # i.e. np.ufunc.__call__ + # NOTE: this false false positive caused by a bug in the `functools` mypy plugin + (KACF, partial(np.add, 1, 1)), # type: ignore[misc] (ACF, partial(np.reshape, AR, 1)), (KACF, partial(np.ravel, AR)), (KACF, partial(np.asarray, 1)), diff --git a/test/runtime/accept/ufuncs.py b/test/runtime/accept/ufuncs.py index 70ba546e..0936dce3 100644 --- a/test/runtime/accept/ufuncs.py +++ b/test/runtime/accept/ufuncs.py @@ -1,3 +1,5 @@ +from collections.abc import Callable + import numpy as np np.sin(1) @@ -22,3 +24,17 @@ u21: np.ufunc = np.gcd u22: np.ufunc = np.divmod gu21: np.ufunc = np.matmul + +f11: Callable[..., object] = np.log +f11_alias: Callable[..., object] = np.abs +f12: Callable[..., object] = np.modf +f21: Callable[..., object] = np.gcd +f22: Callable[..., object] = np.divmod +gf21: Callable[..., object] = np.matmul + +c11: Callable[..., object] = np.log.__call__ +c11_alias: Callable[..., object] = np.abs.__call__ +c12: Callable[..., object] = np.modf.__call__ +c21: Callable[..., object] = np.gcd.__call__ +c22: Callable[..., object] = np.divmod.__call__ +gc21: Callable[..., object] = np.matmul.__call__