diff options
Diffstat (limited to '.venv/lib/python3.12/site-packages/numpy/_typing')
27 files changed, 2323 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__init__.py b/.venv/lib/python3.12/site-packages/numpy/_typing/__init__.py new file mode 100644 index 0000000..16a7eee --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__init__.py @@ -0,0 +1,148 @@ +"""Private counterpart of ``numpy.typing``.""" + +from ._array_like import ArrayLike as ArrayLike +from ._array_like import NDArray as NDArray +from ._array_like import _ArrayLike as _ArrayLike +from ._array_like import _ArrayLikeAnyString_co as _ArrayLikeAnyString_co +from ._array_like import _ArrayLikeBool_co as _ArrayLikeBool_co +from ._array_like import _ArrayLikeBytes_co as _ArrayLikeBytes_co +from ._array_like import _ArrayLikeComplex128_co as _ArrayLikeComplex128_co +from ._array_like import _ArrayLikeComplex_co as _ArrayLikeComplex_co +from ._array_like import _ArrayLikeDT64_co as _ArrayLikeDT64_co +from ._array_like import _ArrayLikeFloat64_co as _ArrayLikeFloat64_co +from ._array_like import _ArrayLikeFloat_co as _ArrayLikeFloat_co +from ._array_like import _ArrayLikeInt as _ArrayLikeInt +from ._array_like import _ArrayLikeInt_co as _ArrayLikeInt_co +from ._array_like import _ArrayLikeNumber_co as _ArrayLikeNumber_co +from ._array_like import _ArrayLikeObject_co as _ArrayLikeObject_co +from ._array_like import _ArrayLikeStr_co as _ArrayLikeStr_co +from ._array_like import _ArrayLikeString_co as _ArrayLikeString_co +from ._array_like import _ArrayLikeTD64_co as _ArrayLikeTD64_co +from ._array_like import _ArrayLikeUInt_co as _ArrayLikeUInt_co +from ._array_like import _ArrayLikeVoid_co as _ArrayLikeVoid_co +from ._array_like import _FiniteNestedSequence as _FiniteNestedSequence +from ._array_like import _SupportsArray as _SupportsArray +from ._array_like import _SupportsArrayFunc as _SupportsArrayFunc + +# +from ._char_codes import _BoolCodes as _BoolCodes +from ._char_codes import _ByteCodes as _ByteCodes +from ._char_codes import _BytesCodes as _BytesCodes +from ._char_codes import _CDoubleCodes as _CDoubleCodes +from ._char_codes import _CharacterCodes as _CharacterCodes +from ._char_codes import _CLongDoubleCodes as _CLongDoubleCodes +from ._char_codes import _Complex64Codes as _Complex64Codes +from ._char_codes import _Complex128Codes as _Complex128Codes +from ._char_codes import _ComplexFloatingCodes as _ComplexFloatingCodes +from ._char_codes import _CSingleCodes as _CSingleCodes +from ._char_codes import _DoubleCodes as _DoubleCodes +from ._char_codes import _DT64Codes as _DT64Codes +from ._char_codes import _FlexibleCodes as _FlexibleCodes +from ._char_codes import _Float16Codes as _Float16Codes +from ._char_codes import _Float32Codes as _Float32Codes +from ._char_codes import _Float64Codes as _Float64Codes +from ._char_codes import _FloatingCodes as _FloatingCodes +from ._char_codes import _GenericCodes as _GenericCodes +from ._char_codes import _HalfCodes as _HalfCodes +from ._char_codes import _InexactCodes as _InexactCodes +from ._char_codes import _Int8Codes as _Int8Codes +from ._char_codes import _Int16Codes as _Int16Codes +from ._char_codes import _Int32Codes as _Int32Codes +from ._char_codes import _Int64Codes as _Int64Codes +from ._char_codes import _IntCCodes as _IntCCodes +from ._char_codes import _IntCodes as _IntCodes +from ._char_codes import _IntegerCodes as _IntegerCodes +from ._char_codes import _IntPCodes as _IntPCodes +from ._char_codes import _LongCodes as _LongCodes +from ._char_codes import _LongDoubleCodes as _LongDoubleCodes +from ._char_codes import _LongLongCodes as _LongLongCodes +from ._char_codes import _NumberCodes as _NumberCodes +from ._char_codes import _ObjectCodes as _ObjectCodes +from ._char_codes import _ShortCodes as _ShortCodes +from ._char_codes import _SignedIntegerCodes as _SignedIntegerCodes +from ._char_codes import _SingleCodes as _SingleCodes +from ._char_codes import _StrCodes as _StrCodes +from ._char_codes import _StringCodes as _StringCodes +from ._char_codes import _TD64Codes as _TD64Codes +from ._char_codes import _UByteCodes as _UByteCodes +from ._char_codes import _UInt8Codes as _UInt8Codes +from ._char_codes import _UInt16Codes as _UInt16Codes +from ._char_codes import _UInt32Codes as _UInt32Codes +from ._char_codes import _UInt64Codes as _UInt64Codes +from ._char_codes import _UIntCCodes as _UIntCCodes +from ._char_codes import _UIntCodes as _UIntCodes +from ._char_codes import _UIntPCodes as _UIntPCodes +from ._char_codes import _ULongCodes as _ULongCodes +from ._char_codes import _ULongLongCodes as _ULongLongCodes +from ._char_codes import _UnsignedIntegerCodes as _UnsignedIntegerCodes +from ._char_codes import _UShortCodes as _UShortCodes +from ._char_codes import _VoidCodes as _VoidCodes + +# +from ._dtype_like import DTypeLike as DTypeLike +from ._dtype_like import _DTypeLike as _DTypeLike +from ._dtype_like import _DTypeLikeBool as _DTypeLikeBool +from ._dtype_like import _DTypeLikeBytes as _DTypeLikeBytes +from ._dtype_like import _DTypeLikeComplex as _DTypeLikeComplex +from ._dtype_like import _DTypeLikeComplex_co as _DTypeLikeComplex_co +from ._dtype_like import _DTypeLikeDT64 as _DTypeLikeDT64 +from ._dtype_like import _DTypeLikeFloat as _DTypeLikeFloat +from ._dtype_like import _DTypeLikeInt as _DTypeLikeInt +from ._dtype_like import _DTypeLikeObject as _DTypeLikeObject +from ._dtype_like import _DTypeLikeStr as _DTypeLikeStr +from ._dtype_like import _DTypeLikeTD64 as _DTypeLikeTD64 +from ._dtype_like import _DTypeLikeUInt as _DTypeLikeUInt +from ._dtype_like import _DTypeLikeVoid as _DTypeLikeVoid +from ._dtype_like import _SupportsDType as _SupportsDType +from ._dtype_like import _VoidDTypeLike as _VoidDTypeLike + +# +from ._nbit import _NBitByte as _NBitByte +from ._nbit import _NBitDouble as _NBitDouble +from ._nbit import _NBitHalf as _NBitHalf +from ._nbit import _NBitInt as _NBitInt +from ._nbit import _NBitIntC as _NBitIntC +from ._nbit import _NBitIntP as _NBitIntP +from ._nbit import _NBitLong as _NBitLong +from ._nbit import _NBitLongDouble as _NBitLongDouble +from ._nbit import _NBitLongLong as _NBitLongLong +from ._nbit import _NBitShort as _NBitShort +from ._nbit import _NBitSingle as _NBitSingle + +# +from ._nbit_base import ( + NBitBase as NBitBase, # type: ignore[deprecated] # pyright: ignore[reportDeprecated] +) +from ._nbit_base import _8Bit as _8Bit +from ._nbit_base import _16Bit as _16Bit +from ._nbit_base import _32Bit as _32Bit +from ._nbit_base import _64Bit as _64Bit +from ._nbit_base import _96Bit as _96Bit +from ._nbit_base import _128Bit as _128Bit + +# +from ._nested_sequence import _NestedSequence as _NestedSequence + +# +from ._scalars import _BoolLike_co as _BoolLike_co +from ._scalars import _CharLike_co as _CharLike_co +from ._scalars import _ComplexLike_co as _ComplexLike_co +from ._scalars import _FloatLike_co as _FloatLike_co +from ._scalars import _IntLike_co as _IntLike_co +from ._scalars import _NumberLike_co as _NumberLike_co +from ._scalars import _ScalarLike_co as _ScalarLike_co +from ._scalars import _TD64Like_co as _TD64Like_co +from ._scalars import _UIntLike_co as _UIntLike_co +from ._scalars import _VoidLike_co as _VoidLike_co + +# +from ._shape import _AnyShape as _AnyShape +from ._shape import _Shape as _Shape +from ._shape import _ShapeLike as _ShapeLike + +# +from ._ufunc import _GUFunc_Nin2_Nout1 as _GUFunc_Nin2_Nout1 +from ._ufunc import _UFunc_Nin1_Nout1 as _UFunc_Nin1_Nout1 +from ._ufunc import _UFunc_Nin1_Nout2 as _UFunc_Nin1_Nout2 +from ._ufunc import _UFunc_Nin2_Nout1 as _UFunc_Nin2_Nout1 +from ._ufunc import _UFunc_Nin2_Nout2 as _UFunc_Nin2_Nout2 diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/__init__.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/__init__.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..67d4164 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/__init__.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_add_docstring.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_add_docstring.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..e44c917 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_add_docstring.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_array_like.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_array_like.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..b2f82de --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_array_like.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_char_codes.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_char_codes.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..afdba3e --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_char_codes.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_dtype_like.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_dtype_like.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..9253e6b --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_dtype_like.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_extended_precision.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_extended_precision.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..2c06b47 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_extended_precision.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nbit.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nbit.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..2ece775 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nbit.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nbit_base.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nbit_base.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..3794b7a --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nbit_base.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nested_sequence.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nested_sequence.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..67f2737 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_nested_sequence.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_scalars.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_scalars.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..85f31c2 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_scalars.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_shape.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_shape.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..b439f4b --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_shape.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_ufunc.cpython-312.pyc b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_ufunc.cpython-312.pyc Binary files differnew file mode 100644 index 0000000..c625672 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/__pycache__/_ufunc.cpython-312.pyc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_add_docstring.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_add_docstring.py new file mode 100644 index 0000000..5330a6b --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_add_docstring.py @@ -0,0 +1,153 @@ +"""A module for creating docstrings for sphinx ``data`` domains.""" + +import re +import textwrap + +from ._array_like import NDArray + +_docstrings_list = [] + + +def add_newdoc(name: str, value: str, doc: str) -> None: + """Append ``_docstrings_list`` with a docstring for `name`. + + Parameters + ---------- + name : str + The name of the object. + value : str + A string-representation of the object. + doc : str + The docstring of the object. + + """ + _docstrings_list.append((name, value, doc)) + + +def _parse_docstrings() -> str: + """Convert all docstrings in ``_docstrings_list`` into a single + sphinx-legible text block. + + """ + type_list_ret = [] + for name, value, doc in _docstrings_list: + s = textwrap.dedent(doc).replace("\n", "\n ") + + # Replace sections by rubrics + lines = s.split("\n") + new_lines = [] + indent = "" + for line in lines: + m = re.match(r'^(\s+)[-=]+\s*$', line) + if m and new_lines: + prev = textwrap.dedent(new_lines.pop()) + if prev == "Examples": + indent = "" + new_lines.append(f'{m.group(1)}.. rubric:: {prev}') + else: + indent = 4 * " " + new_lines.append(f'{m.group(1)}.. admonition:: {prev}') + new_lines.append("") + else: + new_lines.append(f"{indent}{line}") + + s = "\n".join(new_lines) + s_block = f""".. data:: {name}\n :value: {value}\n {s}""" + type_list_ret.append(s_block) + return "\n".join(type_list_ret) + + +add_newdoc('ArrayLike', 'typing.Union[...]', + """ + A `~typing.Union` representing objects that can be coerced + into an `~numpy.ndarray`. + + Among others this includes the likes of: + + * Scalars. + * (Nested) sequences. + * Objects implementing the `~class.__array__` protocol. + + .. versionadded:: 1.20 + + See Also + -------- + :term:`array_like`: + Any scalar or sequence that can be interpreted as an ndarray. + + Examples + -------- + .. code-block:: python + + >>> import numpy as np + >>> import numpy.typing as npt + + >>> def as_array(a: npt.ArrayLike) -> np.ndarray: + ... return np.array(a) + + """) + +add_newdoc('DTypeLike', 'typing.Union[...]', + """ + A `~typing.Union` representing objects that can be coerced + into a `~numpy.dtype`. + + Among others this includes the likes of: + + * :class:`type` objects. + * Character codes or the names of :class:`type` objects. + * Objects with the ``.dtype`` attribute. + + .. versionadded:: 1.20 + + See Also + -------- + :ref:`Specifying and constructing data types <arrays.dtypes.constructing>` + A comprehensive overview of all objects that can be coerced + into data types. + + Examples + -------- + .. code-block:: python + + >>> import numpy as np + >>> import numpy.typing as npt + + >>> def as_dtype(d: npt.DTypeLike) -> np.dtype: + ... return np.dtype(d) + + """) + +add_newdoc('NDArray', repr(NDArray), + """ + A `np.ndarray[tuple[Any, ...], np.dtype[ScalarT]] <numpy.ndarray>` + type alias :term:`generic <generic type>` w.r.t. its + `dtype.type <numpy.dtype.type>`. + + Can be used during runtime for typing arrays with a given dtype + and unspecified shape. + + .. versionadded:: 1.21 + + Examples + -------- + .. code-block:: python + + >>> import numpy as np + >>> import numpy.typing as npt + + >>> print(npt.NDArray) + numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[~_ScalarT]] + + >>> print(npt.NDArray[np.float64]) + numpy.ndarray[tuple[typing.Any, ...], numpy.dtype[numpy.float64]] + + >>> NDArrayInt = npt.NDArray[np.int_] + >>> a: NDArrayInt = np.arange(10) + + >>> def func(a: npt.ArrayLike) -> npt.NDArray[Any]: + ... return np.array(a) + + """) + +_docstrings = _parse_docstrings() diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_array_like.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_array_like.py new file mode 100644 index 0000000..6b071f4 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_array_like.py @@ -0,0 +1,106 @@ +import sys +from collections.abc import Callable, Collection, Sequence +from typing import TYPE_CHECKING, Any, Protocol, TypeAlias, TypeVar, runtime_checkable + +import numpy as np +from numpy import dtype + +from ._nbit_base import _32Bit, _64Bit +from ._nested_sequence import _NestedSequence +from ._shape import _AnyShape + +if TYPE_CHECKING: + StringDType = np.dtypes.StringDType +else: + # at runtime outside of type checking importing this from numpy.dtypes + # would lead to a circular import + from numpy._core.multiarray import StringDType + +_T = TypeVar("_T") +_ScalarT = TypeVar("_ScalarT", bound=np.generic) +_DTypeT = TypeVar("_DTypeT", bound=dtype[Any]) +_DTypeT_co = TypeVar("_DTypeT_co", covariant=True, bound=dtype[Any]) + +NDArray: TypeAlias = np.ndarray[_AnyShape, dtype[_ScalarT]] + +# The `_SupportsArray` protocol only cares about the default dtype +# (i.e. `dtype=None` or no `dtype` parameter at all) of the to-be returned +# array. +# Concrete implementations of the protocol are responsible for adding +# any and all remaining overloads +@runtime_checkable +class _SupportsArray(Protocol[_DTypeT_co]): + def __array__(self) -> np.ndarray[Any, _DTypeT_co]: ... + + +@runtime_checkable +class _SupportsArrayFunc(Protocol): + """A protocol class representing `~class.__array_function__`.""" + def __array_function__( + self, + func: Callable[..., Any], + types: Collection[type[Any]], + args: tuple[Any, ...], + kwargs: dict[str, Any], + ) -> object: ... + + +# TODO: Wait until mypy supports recursive objects in combination with typevars +_FiniteNestedSequence: TypeAlias = ( + _T + | Sequence[_T] + | Sequence[Sequence[_T]] + | Sequence[Sequence[Sequence[_T]]] + | Sequence[Sequence[Sequence[Sequence[_T]]]] +) + +# A subset of `npt.ArrayLike` that can be parametrized w.r.t. `np.generic` +_ArrayLike: TypeAlias = ( + _SupportsArray[dtype[_ScalarT]] + | _NestedSequence[_SupportsArray[dtype[_ScalarT]]] +) + +# A union representing array-like objects; consists of two typevars: +# One representing types that can be parametrized w.r.t. `np.dtype` +# and another one for the rest +_DualArrayLike: TypeAlias = ( + _SupportsArray[_DTypeT] + | _NestedSequence[_SupportsArray[_DTypeT]] + | _T + | _NestedSequence[_T] +) + +if sys.version_info >= (3, 12): + from collections.abc import Buffer as _Buffer +else: + @runtime_checkable + class _Buffer(Protocol): + def __buffer__(self, flags: int, /) -> memoryview: ... + +ArrayLike: TypeAlias = _Buffer | _DualArrayLike[dtype[Any], complex | bytes | str] + +# `ArrayLike<X>_co`: array-like objects that can be coerced into `X` +# given the casting rules `same_kind` +_ArrayLikeBool_co: TypeAlias = _DualArrayLike[dtype[np.bool], bool] +_ArrayLikeUInt_co: TypeAlias = _DualArrayLike[dtype[np.bool | np.unsignedinteger], bool] +_ArrayLikeInt_co: TypeAlias = _DualArrayLike[dtype[np.bool | np.integer], int] +_ArrayLikeFloat_co: TypeAlias = _DualArrayLike[dtype[np.bool | np.integer | np.floating], float] +_ArrayLikeComplex_co: TypeAlias = _DualArrayLike[dtype[np.bool | np.number], complex] +_ArrayLikeNumber_co: TypeAlias = _ArrayLikeComplex_co +_ArrayLikeTD64_co: TypeAlias = _DualArrayLike[dtype[np.bool | np.integer | np.timedelta64], int] +_ArrayLikeDT64_co: TypeAlias = _ArrayLike[np.datetime64] +_ArrayLikeObject_co: TypeAlias = _ArrayLike[np.object_] + +_ArrayLikeVoid_co: TypeAlias = _ArrayLike[np.void] +_ArrayLikeBytes_co: TypeAlias = _DualArrayLike[dtype[np.bytes_], bytes] +_ArrayLikeStr_co: TypeAlias = _DualArrayLike[dtype[np.str_], str] +_ArrayLikeString_co: TypeAlias = _DualArrayLike[StringDType, str] +_ArrayLikeAnyString_co: TypeAlias = _DualArrayLike[dtype[np.character] | StringDType, bytes | str] + +__Float64_co: TypeAlias = np.floating[_64Bit] | np.float32 | np.float16 | np.integer | np.bool +__Complex128_co: TypeAlias = np.number[_64Bit] | np.number[_32Bit] | np.float16 | np.integer | np.bool +_ArrayLikeFloat64_co: TypeAlias = _DualArrayLike[dtype[__Float64_co], float] +_ArrayLikeComplex128_co: TypeAlias = _DualArrayLike[dtype[__Complex128_co], complex] + +# NOTE: This includes `builtins.bool`, but not `numpy.bool`. +_ArrayLikeInt: TypeAlias = _DualArrayLike[dtype[np.integer], int] diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_callable.pyi b/.venv/lib/python3.12/site-packages/numpy/_typing/_callable.pyi new file mode 100644 index 0000000..21df1d9 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_callable.pyi @@ -0,0 +1,366 @@ +""" +A module with various ``typing.Protocol`` subclasses that implement +the ``__call__`` magic method. + +See the `Mypy documentation`_ on protocols for more details. + +.. _`Mypy documentation`: https://mypy.readthedocs.io/en/stable/protocols.html#callback-protocols + +""" + +from typing import ( + Any, + NoReturn, + Protocol, + TypeAlias, + TypeVar, + final, + overload, + type_check_only, +) + +import numpy as np +from numpy import ( + complex128, + complexfloating, + float64, + floating, + generic, + int8, + int_, + integer, + number, + signedinteger, + unsignedinteger, +) + +from . import NBitBase +from ._array_like import NDArray +from ._nbit import _NBitInt +from ._nested_sequence import _NestedSequence +from ._scalars import ( + _BoolLike_co, + _IntLike_co, + _NumberLike_co, +) + +_T1 = TypeVar("_T1") +_T2 = TypeVar("_T2") +_T1_contra = TypeVar("_T1_contra", contravariant=True) +_T2_contra = TypeVar("_T2_contra", contravariant=True) + +_2Tuple: TypeAlias = tuple[_T1, _T1] + +_NBit1 = TypeVar("_NBit1", bound=NBitBase) +_NBit2 = TypeVar("_NBit2", bound=NBitBase) + +_IntType = TypeVar("_IntType", bound=integer) +_FloatType = TypeVar("_FloatType", bound=floating) +_NumberType = TypeVar("_NumberType", bound=number) +_NumberType_co = TypeVar("_NumberType_co", covariant=True, bound=number) +_GenericType_co = TypeVar("_GenericType_co", covariant=True, bound=generic) + +@type_check_only +class _BoolOp(Protocol[_GenericType_co]): + @overload + def __call__(self, other: _BoolLike_co, /) -> _GenericType_co: ... + @overload # platform dependent + def __call__(self, other: int, /) -> int_: ... + @overload + def __call__(self, other: float, /) -> float64: ... + @overload + def __call__(self, other: complex, /) -> complex128: ... + @overload + def __call__(self, other: _NumberType, /) -> _NumberType: ... + +@type_check_only +class _BoolBitOp(Protocol[_GenericType_co]): + @overload + def __call__(self, other: _BoolLike_co, /) -> _GenericType_co: ... + @overload # platform dependent + def __call__(self, other: int, /) -> int_: ... + @overload + def __call__(self, other: _IntType, /) -> _IntType: ... + +@type_check_only +class _BoolSub(Protocol): + # Note that `other: bool` is absent here + @overload + def __call__(self, other: bool, /) -> NoReturn: ... + @overload # platform dependent + def __call__(self, other: int, /) -> int_: ... + @overload + def __call__(self, other: float, /) -> float64: ... + @overload + def __call__(self, other: complex, /) -> complex128: ... + @overload + def __call__(self, other: _NumberType, /) -> _NumberType: ... + +@type_check_only +class _BoolTrueDiv(Protocol): + @overload + def __call__(self, other: float | _IntLike_co, /) -> float64: ... + @overload + def __call__(self, other: complex, /) -> complex128: ... + @overload + def __call__(self, other: _NumberType, /) -> _NumberType: ... + +@type_check_only +class _BoolMod(Protocol): + @overload + def __call__(self, other: _BoolLike_co, /) -> int8: ... + @overload # platform dependent + def __call__(self, other: int, /) -> int_: ... + @overload + def __call__(self, other: float, /) -> float64: ... + @overload + def __call__(self, other: _IntType, /) -> _IntType: ... + @overload + def __call__(self, other: _FloatType, /) -> _FloatType: ... + +@type_check_only +class _BoolDivMod(Protocol): + @overload + def __call__(self, other: _BoolLike_co, /) -> _2Tuple[int8]: ... + @overload # platform dependent + def __call__(self, other: int, /) -> _2Tuple[int_]: ... + @overload + def __call__(self, other: float, /) -> _2Tuple[np.float64]: ... + @overload + def __call__(self, other: _IntType, /) -> _2Tuple[_IntType]: ... + @overload + def __call__(self, other: _FloatType, /) -> _2Tuple[_FloatType]: ... + +@type_check_only +class _IntTrueDiv(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> floating[_NBit1]: ... + @overload + def __call__(self, other: int, /) -> floating[_NBit1] | floating[_NBitInt]: ... + @overload + def __call__(self, other: float, /) -> floating[_NBit1] | float64: ... + @overload + def __call__( + self, other: complex, / + ) -> complexfloating[_NBit1, _NBit1] | complex128: ... + @overload + def __call__( + self, other: integer[_NBit2], / + ) -> floating[_NBit1] | floating[_NBit2]: ... + +@type_check_only +class _UnsignedIntOp(Protocol[_NBit1]): + # NOTE: `uint64 + signedinteger -> float64` + @overload + def __call__(self, other: int, /) -> unsignedinteger[_NBit1]: ... + @overload + def __call__(self, other: float, /) -> float64: ... + @overload + def __call__(self, other: complex, /) -> complex128: ... + @overload + def __call__(self, other: unsignedinteger[_NBit2], /) -> unsignedinteger[_NBit1] | unsignedinteger[_NBit2]: ... + @overload + def __call__(self, other: signedinteger, /) -> Any: ... + +@type_check_only +class _UnsignedIntBitOp(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> unsignedinteger[_NBit1]: ... + @overload + def __call__(self, other: int, /) -> signedinteger: ... + @overload + def __call__(self, other: signedinteger, /) -> signedinteger: ... + @overload + def __call__( + self, other: unsignedinteger[_NBit2], / + ) -> unsignedinteger[_NBit1] | unsignedinteger[_NBit2]: ... + +@type_check_only +class _UnsignedIntMod(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> unsignedinteger[_NBit1]: ... + @overload + def __call__(self, other: int | signedinteger, /) -> Any: ... + @overload + def __call__(self, other: float, /) -> floating[_NBit1] | float64: ... + @overload + def __call__( + self, other: unsignedinteger[_NBit2], / + ) -> unsignedinteger[_NBit1] | unsignedinteger[_NBit2]: ... + +@type_check_only +class _UnsignedIntDivMod(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> _2Tuple[signedinteger[_NBit1]]: ... + @overload + def __call__(self, other: int | signedinteger, /) -> _2Tuple[Any]: ... + @overload + def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1]] | _2Tuple[float64]: ... + @overload + def __call__( + self, other: unsignedinteger[_NBit2], / + ) -> _2Tuple[unsignedinteger[_NBit1]] | _2Tuple[unsignedinteger[_NBit2]]: ... + +@type_check_only +class _SignedIntOp(Protocol[_NBit1]): + @overload + def __call__(self, other: int, /) -> signedinteger[_NBit1]: ... + @overload + def __call__(self, other: float, /) -> float64: ... + @overload + def __call__(self, other: complex, /) -> complex128: ... + @overload + def __call__(self, other: signedinteger[_NBit2], /) -> signedinteger[_NBit1] | signedinteger[_NBit2]: ... + +@type_check_only +class _SignedIntBitOp(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ... + @overload + def __call__(self, other: int, /) -> signedinteger[_NBit1] | int_: ... + @overload + def __call__( + self, other: signedinteger[_NBit2], / + ) -> signedinteger[_NBit1] | signedinteger[_NBit2]: ... + +@type_check_only +class _SignedIntMod(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> signedinteger[_NBit1]: ... + @overload + def __call__(self, other: int, /) -> signedinteger[_NBit1] | int_: ... + @overload + def __call__(self, other: float, /) -> floating[_NBit1] | float64: ... + @overload + def __call__( + self, other: signedinteger[_NBit2], / + ) -> signedinteger[_NBit1] | signedinteger[_NBit2]: ... + +@type_check_only +class _SignedIntDivMod(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> _2Tuple[signedinteger[_NBit1]]: ... + @overload + def __call__(self, other: int, /) -> _2Tuple[signedinteger[_NBit1]] | _2Tuple[int_]: ... + @overload + def __call__(self, other: float, /) -> _2Tuple[floating[_NBit1]] | _2Tuple[float64]: ... + @overload + def __call__( + self, other: signedinteger[_NBit2], / + ) -> _2Tuple[signedinteger[_NBit1]] | _2Tuple[signedinteger[_NBit2]]: ... + +@type_check_only +class _FloatOp(Protocol[_NBit1]): + @overload + def __call__(self, other: int, /) -> floating[_NBit1]: ... + @overload + def __call__(self, other: float, /) -> floating[_NBit1] | float64: ... + @overload + def __call__( + self, other: complex, / + ) -> complexfloating[_NBit1, _NBit1] | complex128: ... + @overload + def __call__( + self, other: integer[_NBit2] | floating[_NBit2], / + ) -> floating[_NBit1] | floating[_NBit2]: ... + +@type_check_only +class _FloatMod(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> floating[_NBit1]: ... + @overload + def __call__(self, other: int, /) -> floating[_NBit1] | floating[_NBitInt]: ... + @overload + def __call__(self, other: float, /) -> floating[_NBit1] | float64: ... + @overload + def __call__( + self, other: integer[_NBit2] | floating[_NBit2], / + ) -> floating[_NBit1] | floating[_NBit2]: ... + +class _FloatDivMod(Protocol[_NBit1]): + @overload + def __call__(self, other: bool, /) -> _2Tuple[floating[_NBit1]]: ... + @overload + def __call__( + self, other: int, / + ) -> _2Tuple[floating[_NBit1]] | _2Tuple[floating[_NBitInt]]: ... + @overload + def __call__( + self, other: float, / + ) -> _2Tuple[floating[_NBit1]] | _2Tuple[float64]: ... + @overload + def __call__( + self, other: integer[_NBit2] | floating[_NBit2], / + ) -> _2Tuple[floating[_NBit1]] | _2Tuple[floating[_NBit2]]: ... + +@type_check_only +class _NumberOp(Protocol): + def __call__(self, other: _NumberLike_co, /) -> Any: ... + +@final +@type_check_only +class _SupportsLT(Protocol): + def __lt__(self, other: Any, /) -> Any: ... + +@final +@type_check_only +class _SupportsLE(Protocol): + def __le__(self, other: Any, /) -> Any: ... + +@final +@type_check_only +class _SupportsGT(Protocol): + def __gt__(self, other: Any, /) -> Any: ... + +@final +@type_check_only +class _SupportsGE(Protocol): + def __ge__(self, other: Any, /) -> Any: ... + +@final +@type_check_only +class _ComparisonOpLT(Protocol[_T1_contra, _T2_contra]): + @overload + def __call__(self, other: _T1_contra, /) -> np.bool: ... + @overload + def __call__(self, other: _T2_contra, /) -> NDArray[np.bool]: ... + @overload + def __call__(self, other: _NestedSequence[_SupportsGT], /) -> NDArray[np.bool]: ... + @overload + def __call__(self, other: _SupportsGT, /) -> np.bool: ... + +@final +@type_check_only +class _ComparisonOpLE(Protocol[_T1_contra, _T2_contra]): + @overload + def __call__(self, other: _T1_contra, /) -> np.bool: ... + @overload + def __call__(self, other: _T2_contra, /) -> NDArray[np.bool]: ... + @overload + def __call__(self, other: _NestedSequence[_SupportsGE], /) -> NDArray[np.bool]: ... + @overload + def __call__(self, other: _SupportsGE, /) -> np.bool: ... + +@final +@type_check_only +class _ComparisonOpGT(Protocol[_T1_contra, _T2_contra]): + @overload + def __call__(self, other: _T1_contra, /) -> np.bool: ... + @overload + def __call__(self, other: _T2_contra, /) -> NDArray[np.bool]: ... + @overload + def __call__(self, other: _NestedSequence[_SupportsLT], /) -> NDArray[np.bool]: ... + @overload + def __call__(self, other: _SupportsLT, /) -> np.bool: ... + +@final +@type_check_only +class _ComparisonOpGE(Protocol[_T1_contra, _T2_contra]): + @overload + def __call__(self, other: _T1_contra, /) -> np.bool: ... + @overload + def __call__(self, other: _T2_contra, /) -> NDArray[np.bool]: ... + @overload + def __call__(self, other: _NestedSequence[_SupportsGT], /) -> NDArray[np.bool]: ... + @overload + def __call__(self, other: _SupportsGT, /) -> np.bool: ... diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_char_codes.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_char_codes.py new file mode 100644 index 0000000..7b6fad2 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_char_codes.py @@ -0,0 +1,213 @@ +from typing import Literal + +_BoolCodes = Literal[ + "bool", "bool_", + "?", "|?", "=?", "<?", ">?", + "b1", "|b1", "=b1", "<b1", ">b1", +] # fmt: skip + +_UInt8Codes = Literal["uint8", "u1", "|u1", "=u1", "<u1", ">u1"] +_UInt16Codes = Literal["uint16", "u2", "|u2", "=u2", "<u2", ">u2"] +_UInt32Codes = Literal["uint32", "u4", "|u4", "=u4", "<u4", ">u4"] +_UInt64Codes = Literal["uint64", "u8", "|u8", "=u8", "<u8", ">u8"] + +_Int8Codes = Literal["int8", "i1", "|i1", "=i1", "<i1", ">i1"] +_Int16Codes = Literal["int16", "i2", "|i2", "=i2", "<i2", ">i2"] +_Int32Codes = Literal["int32", "i4", "|i4", "=i4", "<i4", ">i4"] +_Int64Codes = Literal["int64", "i8", "|i8", "=i8", "<i8", ">i8"] + +_Float16Codes = Literal["float16", "f2", "|f2", "=f2", "<f2", ">f2"] +_Float32Codes = Literal["float32", "f4", "|f4", "=f4", "<f4", ">f4"] +_Float64Codes = Literal["float64", "f8", "|f8", "=f8", "<f8", ">f8"] + +_Complex64Codes = Literal["complex64", "c8", "|c8", "=c8", "<c8", ">c8"] +_Complex128Codes = Literal["complex128", "c16", "|c16", "=c16", "<c16", ">c16"] + +_ByteCodes = Literal["byte", "b", "|b", "=b", "<b", ">b"] +_ShortCodes = Literal["short", "h", "|h", "=h", "<h", ">h"] +_IntCCodes = Literal["intc", "i", "|i", "=i", "<i", ">i"] +_IntPCodes = Literal["intp", "int", "int_", "n", "|n", "=n", "<n", ">n"] +_LongCodes = Literal["long", "l", "|l", "=l", "<l", ">l"] +_IntCodes = _IntPCodes +_LongLongCodes = Literal["longlong", "q", "|q", "=q", "<q", ">q"] + +_UByteCodes = Literal["ubyte", "B", "|B", "=B", "<B", ">B"] +_UShortCodes = Literal["ushort", "H", "|H", "=H", "<H", ">H"] +_UIntCCodes = Literal["uintc", "I", "|I", "=I", "<I", ">I"] +_UIntPCodes = Literal["uintp", "uint", "N", "|N", "=N", "<N", ">N"] +_ULongCodes = Literal["ulong", "L", "|L", "=L", "<L", ">L"] +_UIntCodes = _UIntPCodes +_ULongLongCodes = Literal["ulonglong", "Q", "|Q", "=Q", "<Q", ">Q"] + +_HalfCodes = Literal["half", "e", "|e", "=e", "<e", ">e"] +_SingleCodes = Literal["single", "f", "|f", "=f", "<f", ">f"] +_DoubleCodes = Literal["double", "float", "d", "|d", "=d", "<d", ">d"] +_LongDoubleCodes = Literal["longdouble", "g", "|g", "=g", "<g", ">g"] + +_CSingleCodes = Literal["csingle", "F", "|F", "=F", "<F", ">F"] +_CDoubleCodes = Literal["cdouble", "complex", "D", "|D", "=D", "<D", ">D"] +_CLongDoubleCodes = Literal["clongdouble", "G", "|G", "=G", "<G", ">G"] + +_StrCodes = Literal["str", "str_", "unicode", "U", "|U", "=U", "<U", ">U"] +_BytesCodes = Literal["bytes", "bytes_", "S", "|S", "=S", "<S", ">S"] +_VoidCodes = Literal["void", "V", "|V", "=V", "<V", ">V"] +_ObjectCodes = Literal["object", "object_", "O", "|O", "=O", "<O", ">O"] + +_DT64Codes = Literal[ + "datetime64", "|datetime64", "=datetime64", + "<datetime64", ">datetime64", + "datetime64[Y]", "|datetime64[Y]", "=datetime64[Y]", + "<datetime64[Y]", ">datetime64[Y]", + "datetime64[M]", "|datetime64[M]", "=datetime64[M]", + "<datetime64[M]", ">datetime64[M]", + "datetime64[W]", "|datetime64[W]", "=datetime64[W]", + "<datetime64[W]", ">datetime64[W]", + "datetime64[D]", "|datetime64[D]", "=datetime64[D]", + "<datetime64[D]", ">datetime64[D]", + "datetime64[h]", "|datetime64[h]", "=datetime64[h]", + "<datetime64[h]", ">datetime64[h]", + "datetime64[m]", "|datetime64[m]", "=datetime64[m]", + "<datetime64[m]", ">datetime64[m]", + "datetime64[s]", "|datetime64[s]", "=datetime64[s]", + "<datetime64[s]", ">datetime64[s]", + "datetime64[ms]", "|datetime64[ms]", "=datetime64[ms]", + "<datetime64[ms]", ">datetime64[ms]", + "datetime64[us]", "|datetime64[us]", "=datetime64[us]", + "<datetime64[us]", ">datetime64[us]", + "datetime64[ns]", "|datetime64[ns]", "=datetime64[ns]", + "<datetime64[ns]", ">datetime64[ns]", + "datetime64[ps]", "|datetime64[ps]", "=datetime64[ps]", + "<datetime64[ps]", ">datetime64[ps]", + "datetime64[fs]", "|datetime64[fs]", "=datetime64[fs]", + "<datetime64[fs]", ">datetime64[fs]", + "datetime64[as]", "|datetime64[as]", "=datetime64[as]", + "<datetime64[as]", ">datetime64[as]", + "M", "|M", "=M", "<M", ">M", + "M8", "|M8", "=M8", "<M8", ">M8", + "M8[Y]", "|M8[Y]", "=M8[Y]", "<M8[Y]", ">M8[Y]", + "M8[M]", "|M8[M]", "=M8[M]", "<M8[M]", ">M8[M]", + "M8[W]", "|M8[W]", "=M8[W]", "<M8[W]", ">M8[W]", + "M8[D]", "|M8[D]", "=M8[D]", "<M8[D]", ">M8[D]", + "M8[h]", "|M8[h]", "=M8[h]", "<M8[h]", ">M8[h]", + "M8[m]", "|M8[m]", "=M8[m]", "<M8[m]", ">M8[m]", + "M8[s]", "|M8[s]", "=M8[s]", "<M8[s]", ">M8[s]", + "M8[ms]", "|M8[ms]", "=M8[ms]", "<M8[ms]", ">M8[ms]", + "M8[us]", "|M8[us]", "=M8[us]", "<M8[us]", ">M8[us]", + "M8[ns]", "|M8[ns]", "=M8[ns]", "<M8[ns]", ">M8[ns]", + "M8[ps]", "|M8[ps]", "=M8[ps]", "<M8[ps]", ">M8[ps]", + "M8[fs]", "|M8[fs]", "=M8[fs]", "<M8[fs]", ">M8[fs]", + "M8[as]", "|M8[as]", "=M8[as]", "<M8[as]", ">M8[as]", +] +_TD64Codes = Literal[ + "timedelta64", "|timedelta64", "=timedelta64", + "<timedelta64", ">timedelta64", + "timedelta64[Y]", "|timedelta64[Y]", "=timedelta64[Y]", + "<timedelta64[Y]", ">timedelta64[Y]", + "timedelta64[M]", "|timedelta64[M]", "=timedelta64[M]", + "<timedelta64[M]", ">timedelta64[M]", + "timedelta64[W]", "|timedelta64[W]", "=timedelta64[W]", + "<timedelta64[W]", ">timedelta64[W]", + "timedelta64[D]", "|timedelta64[D]", "=timedelta64[D]", + "<timedelta64[D]", ">timedelta64[D]", + "timedelta64[h]", "|timedelta64[h]", "=timedelta64[h]", + "<timedelta64[h]", ">timedelta64[h]", + "timedelta64[m]", "|timedelta64[m]", "=timedelta64[m]", + "<timedelta64[m]", ">timedelta64[m]", + "timedelta64[s]", "|timedelta64[s]", "=timedelta64[s]", + "<timedelta64[s]", ">timedelta64[s]", + "timedelta64[ms]", "|timedelta64[ms]", "=timedelta64[ms]", + "<timedelta64[ms]", ">timedelta64[ms]", + "timedelta64[us]", "|timedelta64[us]", "=timedelta64[us]", + "<timedelta64[us]", ">timedelta64[us]", + "timedelta64[ns]", "|timedelta64[ns]", "=timedelta64[ns]", + "<timedelta64[ns]", ">timedelta64[ns]", + "timedelta64[ps]", "|timedelta64[ps]", "=timedelta64[ps]", + "<timedelta64[ps]", ">timedelta64[ps]", + "timedelta64[fs]", "|timedelta64[fs]", "=timedelta64[fs]", + "<timedelta64[fs]", ">timedelta64[fs]", + "timedelta64[as]", "|timedelta64[as]", "=timedelta64[as]", + "<timedelta64[as]", ">timedelta64[as]", + "m", "|m", "=m", "<m", ">m", + "m8", "|m8", "=m8", "<m8", ">m8", + "m8[Y]", "|m8[Y]", "=m8[Y]", "<m8[Y]", ">m8[Y]", + "m8[M]", "|m8[M]", "=m8[M]", "<m8[M]", ">m8[M]", + "m8[W]", "|m8[W]", "=m8[W]", "<m8[W]", ">m8[W]", + "m8[D]", "|m8[D]", "=m8[D]", "<m8[D]", ">m8[D]", + "m8[h]", "|m8[h]", "=m8[h]", "<m8[h]", ">m8[h]", + "m8[m]", "|m8[m]", "=m8[m]", "<m8[m]", ">m8[m]", + "m8[s]", "|m8[s]", "=m8[s]", "<m8[s]", ">m8[s]", + "m8[ms]", "|m8[ms]", "=m8[ms]", "<m8[ms]", ">m8[ms]", + "m8[us]", "|m8[us]", "=m8[us]", "<m8[us]", ">m8[us]", + "m8[ns]", "|m8[ns]", "=m8[ns]", "<m8[ns]", ">m8[ns]", + "m8[ps]", "|m8[ps]", "=m8[ps]", "<m8[ps]", ">m8[ps]", + "m8[fs]", "|m8[fs]", "=m8[fs]", "<m8[fs]", ">m8[fs]", + "m8[as]", "|m8[as]", "=m8[as]", "<m8[as]", ">m8[as]", +] + +# NOTE: `StringDType' has no scalar type, and therefore has no name that can +# be passed to the `dtype` constructor +_StringCodes = Literal["T", "|T", "=T", "<T", ">T"] + +# NOTE: Nested literals get flattened and de-duplicated at runtime, which isn't +# the case for a `Union` of `Literal`s. +# So even though they're equivalent when type-checking, they differ at runtime. +# Another advantage of nesting, is that they always have a "flat" +# `Literal.__args__`, which is a tuple of *literally* all its literal values. + +_UnsignedIntegerCodes = Literal[ + _UInt8Codes, + _UInt16Codes, + _UInt32Codes, + _UInt64Codes, + _UIntCodes, + _UByteCodes, + _UShortCodes, + _UIntCCodes, + _ULongCodes, + _ULongLongCodes, +] +_SignedIntegerCodes = Literal[ + _Int8Codes, + _Int16Codes, + _Int32Codes, + _Int64Codes, + _IntCodes, + _ByteCodes, + _ShortCodes, + _IntCCodes, + _LongCodes, + _LongLongCodes, +] +_FloatingCodes = Literal[ + _Float16Codes, + _Float32Codes, + _Float64Codes, + _HalfCodes, + _SingleCodes, + _DoubleCodes, + _LongDoubleCodes +] +_ComplexFloatingCodes = Literal[ + _Complex64Codes, + _Complex128Codes, + _CSingleCodes, + _CDoubleCodes, + _CLongDoubleCodes, +] +_IntegerCodes = Literal[_UnsignedIntegerCodes, _SignedIntegerCodes] +_InexactCodes = Literal[_FloatingCodes, _ComplexFloatingCodes] +_NumberCodes = Literal[_IntegerCodes, _InexactCodes] + +_CharacterCodes = Literal[_StrCodes, _BytesCodes] +_FlexibleCodes = Literal[_VoidCodes, _CharacterCodes] + +_GenericCodes = Literal[ + _BoolCodes, + _NumberCodes, + _FlexibleCodes, + _DT64Codes, + _TD64Codes, + _ObjectCodes, + # TODO: add `_StringCodes` once it has a scalar type + # _StringCodes, +] diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_dtype_like.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_dtype_like.py new file mode 100644 index 0000000..c406b30 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_dtype_like.py @@ -0,0 +1,114 @@ +from collections.abc import Sequence # noqa: F811 +from typing import ( + Any, + Protocol, + TypeAlias, + TypedDict, + TypeVar, + runtime_checkable, +) + +import numpy as np + +from ._char_codes import ( + _BoolCodes, + _BytesCodes, + _ComplexFloatingCodes, + _DT64Codes, + _FloatingCodes, + _NumberCodes, + _ObjectCodes, + _SignedIntegerCodes, + _StrCodes, + _TD64Codes, + _UnsignedIntegerCodes, + _VoidCodes, +) + +_ScalarT = TypeVar("_ScalarT", bound=np.generic) +_DTypeT_co = TypeVar("_DTypeT_co", bound=np.dtype, covariant=True) + +_DTypeLikeNested: TypeAlias = Any # TODO: wait for support for recursive types + + +# Mandatory keys +class _DTypeDictBase(TypedDict): + names: Sequence[str] + formats: Sequence[_DTypeLikeNested] + + +# Mandatory + optional keys +class _DTypeDict(_DTypeDictBase, total=False): + # Only `str` elements are usable as indexing aliases, + # but `titles` can in principle accept any object + offsets: Sequence[int] + titles: Sequence[Any] + itemsize: int + aligned: bool + + +# A protocol for anything with the dtype attribute +@runtime_checkable +class _SupportsDType(Protocol[_DTypeT_co]): + @property + def dtype(self) -> _DTypeT_co: ... + + +# A subset of `npt.DTypeLike` that can be parametrized w.r.t. `np.generic` +_DTypeLike: TypeAlias = type[_ScalarT] | np.dtype[_ScalarT] | _SupportsDType[np.dtype[_ScalarT]] + + +# Would create a dtype[np.void] +_VoidDTypeLike: TypeAlias = ( + # If a tuple, then it can be either: + # - (flexible_dtype, itemsize) + # - (fixed_dtype, shape) + # - (base_dtype, new_dtype) + # But because `_DTypeLikeNested = Any`, the first two cases are redundant + + # tuple[_DTypeLikeNested, int] | tuple[_DTypeLikeNested, _ShapeLike] | + tuple[_DTypeLikeNested, _DTypeLikeNested] + + # [(field_name, field_dtype, field_shape), ...] + # The type here is quite broad because NumPy accepts quite a wide + # range of inputs inside the list; see the tests for some examples. + | list[Any] + + # {'names': ..., 'formats': ..., 'offsets': ..., 'titles': ..., 'itemsize': ...} + | _DTypeDict +) + +# Aliases for commonly used dtype-like objects. +# Note that the precision of `np.number` subclasses is ignored herein. +_DTypeLikeBool: TypeAlias = type[bool] | _DTypeLike[np.bool] | _BoolCodes +_DTypeLikeInt: TypeAlias = ( + type[int] | _DTypeLike[np.signedinteger] | _SignedIntegerCodes +) +_DTypeLikeUInt: TypeAlias = _DTypeLike[np.unsignedinteger] | _UnsignedIntegerCodes +_DTypeLikeFloat: TypeAlias = type[float] | _DTypeLike[np.floating] | _FloatingCodes +_DTypeLikeComplex: TypeAlias = ( + type[complex] | _DTypeLike[np.complexfloating] | _ComplexFloatingCodes +) +_DTypeLikeComplex_co: TypeAlias = ( + type[complex] | _DTypeLike[np.bool | np.number] | _BoolCodes | _NumberCodes +) +_DTypeLikeDT64: TypeAlias = _DTypeLike[np.timedelta64] | _TD64Codes +_DTypeLikeTD64: TypeAlias = _DTypeLike[np.datetime64] | _DT64Codes +_DTypeLikeBytes: TypeAlias = type[bytes] | _DTypeLike[np.bytes_] | _BytesCodes +_DTypeLikeStr: TypeAlias = type[str] | _DTypeLike[np.str_] | _StrCodes +_DTypeLikeVoid: TypeAlias = ( + type[memoryview] | _DTypeLike[np.void] | _VoidDTypeLike | _VoidCodes +) +_DTypeLikeObject: TypeAlias = type[object] | _DTypeLike[np.object_] | _ObjectCodes + + +# Anything that can be coerced into numpy.dtype. +# Reference: https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html +DTypeLike: TypeAlias = _DTypeLike[Any] | _VoidDTypeLike | str | None + +# NOTE: while it is possible to provide the dtype as a dict of +# dtype-like objects (e.g. `{'field1': ..., 'field2': ..., ...}`), +# this syntax is officially discouraged and +# therefore not included in the type-union defining `DTypeLike`. +# +# See https://github.com/numpy/numpy/issues/16891 for more details. diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_extended_precision.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_extended_precision.py new file mode 100644 index 0000000..c707e72 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_extended_precision.py @@ -0,0 +1,15 @@ +"""A module with platform-specific extended precision +`numpy.number` subclasses. + +The subclasses are defined here (instead of ``__init__.pyi``) such +that they can be imported conditionally via the numpy's mypy plugin. +""" + +import numpy as np + +from . import _96Bit, _128Bit + +float96 = np.floating[_96Bit] +float128 = np.floating[_128Bit] +complex192 = np.complexfloating[_96Bit, _96Bit] +complex256 = np.complexfloating[_128Bit, _128Bit] diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit.py new file mode 100644 index 0000000..60bce32 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit.py @@ -0,0 +1,19 @@ +"""A module with the precisions of platform-specific `~numpy.number`s.""" + +from typing import TypeAlias + +from ._nbit_base import _8Bit, _16Bit, _32Bit, _64Bit, _96Bit, _128Bit + +# To-be replaced with a `npt.NBitBase` subclass by numpy's mypy plugin +_NBitByte: TypeAlias = _8Bit +_NBitShort: TypeAlias = _16Bit +_NBitIntC: TypeAlias = _32Bit +_NBitIntP: TypeAlias = _32Bit | _64Bit +_NBitInt: TypeAlias = _NBitIntP +_NBitLong: TypeAlias = _32Bit | _64Bit +_NBitLongLong: TypeAlias = _64Bit + +_NBitHalf: TypeAlias = _16Bit +_NBitSingle: TypeAlias = _32Bit +_NBitDouble: TypeAlias = _64Bit +_NBitLongDouble: TypeAlias = _64Bit | _96Bit | _128Bit diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit_base.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit_base.py new file mode 100644 index 0000000..28d3e63 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit_base.py @@ -0,0 +1,94 @@ +"""A module with the precisions of generic `~numpy.number` types.""" +from typing import final + +from numpy._utils import set_module + + +@final # Disallow the creation of arbitrary `NBitBase` subclasses +@set_module("numpy.typing") +class NBitBase: + """ + A type representing `numpy.number` precision during static type checking. + + Used exclusively for the purpose of static type checking, `NBitBase` + represents the base of a hierarchical set of subclasses. + Each subsequent subclass is herein used for representing a lower level + of precision, *e.g.* ``64Bit > 32Bit > 16Bit``. + + .. versionadded:: 1.20 + + .. deprecated:: 2.3 + Use ``@typing.overload`` or a ``TypeVar`` with a scalar-type as upper + bound, instead. + + Examples + -------- + Below is a typical usage example: `NBitBase` is herein used for annotating + a function that takes a float and integer of arbitrary precision + as arguments and returns a new float of whichever precision is largest + (*e.g.* ``np.float16 + np.int64 -> np.float64``). + + .. code-block:: python + + >>> from typing import TypeVar, TYPE_CHECKING + >>> import numpy as np + >>> import numpy.typing as npt + + >>> S = TypeVar("S", bound=npt.NBitBase) + >>> T = TypeVar("T", bound=npt.NBitBase) + + >>> def add(a: np.floating[S], b: np.integer[T]) -> np.floating[S | T]: + ... return a + b + + >>> a = np.float16() + >>> b = np.int64() + >>> out = add(a, b) + + >>> if TYPE_CHECKING: + ... reveal_locals() + ... # note: Revealed local types are: + ... # note: a: numpy.floating[numpy.typing._16Bit*] + ... # note: b: numpy.signedinteger[numpy.typing._64Bit*] + ... # note: out: numpy.floating[numpy.typing._64Bit*] + + """ + # Deprecated in NumPy 2.3, 2025-05-01 + + def __init_subclass__(cls) -> None: + allowed_names = { + "NBitBase", "_128Bit", "_96Bit", "_64Bit", "_32Bit", "_16Bit", "_8Bit" + } + if cls.__name__ not in allowed_names: + raise TypeError('cannot inherit from final class "NBitBase"') + super().__init_subclass__() + +@final +@set_module("numpy._typing") +# Silence errors about subclassing a `@final`-decorated class +class _128Bit(NBitBase): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + pass + +@final +@set_module("numpy._typing") +class _96Bit(_128Bit): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + pass + +@final +@set_module("numpy._typing") +class _64Bit(_96Bit): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + pass + +@final +@set_module("numpy._typing") +class _32Bit(_64Bit): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + pass + +@final +@set_module("numpy._typing") +class _16Bit(_32Bit): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + pass + +@final +@set_module("numpy._typing") +class _8Bit(_16Bit): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] + pass diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit_base.pyi b/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit_base.pyi new file mode 100644 index 0000000..ccf8f5c --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_nbit_base.pyi @@ -0,0 +1,40 @@ +# pyright: reportDeprecated=false +# pyright: reportGeneralTypeIssues=false +# mypy: disable-error-code=misc + +from typing import final + +from typing_extensions import deprecated + +# Deprecated in NumPy 2.3, 2025-05-01 +@deprecated( + "`NBitBase` is deprecated and will be removed from numpy.typing in the " + "future. Use `@typing.overload` or a `TypeVar` with a scalar-type as upper " + "bound, instead. (deprecated in NumPy 2.3)", +) +@final +class NBitBase: ... + +@final +class _256Bit(NBitBase): ... + +@final +class _128Bit(_256Bit): ... + +@final +class _96Bit(_128Bit): ... + +@final +class _80Bit(_96Bit): ... + +@final +class _64Bit(_80Bit): ... + +@final +class _32Bit(_64Bit): ... + +@final +class _16Bit(_32Bit): ... + +@final +class _8Bit(_16Bit): ... diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_nested_sequence.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_nested_sequence.py new file mode 100644 index 0000000..e3362a9 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_nested_sequence.py @@ -0,0 +1,79 @@ +"""A module containing the `_NestedSequence` protocol.""" + +from typing import TYPE_CHECKING, Any, Protocol, TypeVar, runtime_checkable + +if TYPE_CHECKING: + from collections.abc import Iterator + +__all__ = ["_NestedSequence"] + +_T_co = TypeVar("_T_co", covariant=True) + + +@runtime_checkable +class _NestedSequence(Protocol[_T_co]): + """A protocol for representing nested sequences. + + Warning + ------- + `_NestedSequence` currently does not work in combination with typevars, + *e.g.* ``def func(a: _NestedSequnce[T]) -> T: ...``. + + See Also + -------- + collections.abc.Sequence + ABCs for read-only and mutable :term:`sequences`. + + Examples + -------- + .. code-block:: python + + >>> from typing import TYPE_CHECKING + >>> import numpy as np + >>> from numpy._typing import _NestedSequence + + >>> def get_dtype(seq: _NestedSequence[float]) -> np.dtype[np.float64]: + ... return np.asarray(seq).dtype + + >>> a = get_dtype([1.0]) + >>> b = get_dtype([[1.0]]) + >>> c = get_dtype([[[1.0]]]) + >>> d = get_dtype([[[[1.0]]]]) + + >>> if TYPE_CHECKING: + ... reveal_locals() + ... # note: Revealed local types are: + ... # note: a: numpy.dtype[numpy.floating[numpy._typing._64Bit]] + ... # note: b: numpy.dtype[numpy.floating[numpy._typing._64Bit]] + ... # note: c: numpy.dtype[numpy.floating[numpy._typing._64Bit]] + ... # note: d: numpy.dtype[numpy.floating[numpy._typing._64Bit]] + + """ + + def __len__(self, /) -> int: + """Implement ``len(self)``.""" + raise NotImplementedError + + def __getitem__(self, index: int, /) -> "_T_co | _NestedSequence[_T_co]": + """Implement ``self[x]``.""" + raise NotImplementedError + + def __contains__(self, x: object, /) -> bool: + """Implement ``x in self``.""" + raise NotImplementedError + + def __iter__(self, /) -> "Iterator[_T_co | _NestedSequence[_T_co]]": + """Implement ``iter(self)``.""" + raise NotImplementedError + + def __reversed__(self, /) -> "Iterator[_T_co | _NestedSequence[_T_co]]": + """Implement ``reversed(self)``.""" + raise NotImplementedError + + def count(self, value: Any, /) -> int: + """Return the number of occurrences of `value`.""" + raise NotImplementedError + + def index(self, value: Any, /) -> int: + """Return the first index of `value`.""" + raise NotImplementedError diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_scalars.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_scalars.py new file mode 100644 index 0000000..b0de66d --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_scalars.py @@ -0,0 +1,20 @@ +from typing import Any, TypeAlias + +import numpy as np + +# NOTE: `_StrLike_co` and `_BytesLike_co` are pointless, as `np.str_` and +# `np.bytes_` are already subclasses of their builtin counterpart +_CharLike_co: TypeAlias = str | bytes + +# The `<X>Like_co` type-aliases below represent all scalars that can be +# coerced into `<X>` (with the casting rule `same_kind`) +_BoolLike_co: TypeAlias = bool | np.bool +_UIntLike_co: TypeAlias = bool | np.unsignedinteger | np.bool +_IntLike_co: TypeAlias = int | np.integer | np.bool +_FloatLike_co: TypeAlias = float | np.floating | np.integer | np.bool +_ComplexLike_co: TypeAlias = complex | np.number | np.bool +_NumberLike_co: TypeAlias = _ComplexLike_co +_TD64Like_co: TypeAlias = int | np.timedelta64 | np.integer | np.bool +# `_VoidLike_co` is technically not a scalar, but it's close enough +_VoidLike_co: TypeAlias = tuple[Any, ...] | np.void +_ScalarLike_co: TypeAlias = complex | str | bytes | np.generic diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_shape.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_shape.py new file mode 100644 index 0000000..e297aef --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_shape.py @@ -0,0 +1,8 @@ +from collections.abc import Sequence +from typing import Any, SupportsIndex, TypeAlias + +_Shape: TypeAlias = tuple[int, ...] +_AnyShape: TypeAlias = tuple[Any, ...] + +# Anything that can be coerced to a shape tuple +_ShapeLike: TypeAlias = SupportsIndex | Sequence[SupportsIndex] diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_ufunc.py b/.venv/lib/python3.12/site-packages/numpy/_typing/_ufunc.py new file mode 100644 index 0000000..db52a1f --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_ufunc.py @@ -0,0 +1,7 @@ +from numpy import ufunc + +_UFunc_Nin1_Nout1 = ufunc +_UFunc_Nin2_Nout1 = ufunc +_UFunc_Nin1_Nout2 = ufunc +_UFunc_Nin2_Nout2 = ufunc +_GUFunc_Nin2_Nout1 = ufunc diff --git a/.venv/lib/python3.12/site-packages/numpy/_typing/_ufunc.pyi b/.venv/lib/python3.12/site-packages/numpy/_typing/_ufunc.pyi new file mode 100644 index 0000000..766cde1 --- /dev/null +++ b/.venv/lib/python3.12/site-packages/numpy/_typing/_ufunc.pyi @@ -0,0 +1,941 @@ +"""A module with private type-check-only `numpy.ufunc` subclasses. + +The signatures of the ufuncs are too varied to reasonably type +with a single class. So instead, `ufunc` has been expanded into +four private subclasses, one for each combination of +`~ufunc.nin` and `~ufunc.nout`. +""" + +from typing import ( + Any, + Generic, + Literal, + LiteralString, + NoReturn, + Protocol, + SupportsIndex, + TypeAlias, + TypedDict, + TypeVar, + Unpack, + overload, + type_check_only, +) + +import numpy as np +from numpy import _CastingKind, _OrderKACF, ufunc +from numpy.typing import NDArray + +from ._array_like import ArrayLike, _ArrayLikeBool_co, _ArrayLikeInt_co +from ._dtype_like import DTypeLike +from ._scalars import _ScalarLike_co +from ._shape import _ShapeLike + +_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, *tuple[_T, ...]] +_3PTuple: TypeAlias = tuple[_T, _T, _T, *tuple[_T, ...]] +_4PTuple: TypeAlias = tuple[_T, _T, _T, _T, *tuple[_T, ...]] + +_NTypes = TypeVar("_NTypes", bound=int, covariant=True) +_IDType = TypeVar("_IDType", covariant=True) +_NameType = TypeVar("_NameType", bound=LiteralString, covariant=True) +_Signature = TypeVar("_Signature", bound=LiteralString, covariant=True) + +_NIn = TypeVar("_NIn", bound=int, covariant=True) +_NOut = TypeVar("_NOut", bound=int, covariant=True) +_ReturnType_co = TypeVar("_ReturnType_co", covariant=True) +_ArrayT = TypeVar("_ArrayT", bound=np.ndarray[Any, Any]) + +@type_check_only +class _SupportsArrayUFunc(Protocol): + def __array_ufunc__( + self, + ufunc: ufunc, + method: Literal["__call__", "reduce", "reduceat", "accumulate", "outer", "at"], + *inputs: Any, + **kwargs: Any, + ) -> Any: ... + +@type_check_only +class _UFunc3Kwargs(TypedDict, total=False): + where: _ArrayLikeBool_co | None + 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` + +# NOTE: Similarly, `at` won't be defined for ufuncs that return +# multiple outputs; in such cases `at` is typed to return `NoReturn` + +# 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 + +# pyright: reportIncompatibleMethodOverride=false + +@type_check_only +class _UFunc_Nin1_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc] + @property + def __name__(self) -> _NameType: ... + @property + def __qualname__(self) -> _NameType: ... + @property + def ntypes(self) -> _NTypes: ... + @property + def identity(self) -> _IDType: ... + @property + def nin(self) -> Literal[1]: ... + @property + def nout(self) -> Literal[1]: ... + @property + def nargs(self) -> Literal[2]: ... + @property + def signature(self) -> None: ... + + @overload + def __call__( + self, + __x1: _ScalarLike_co, + out: None = ..., + *, + where: _ArrayLikeBool_co | None = ..., + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _2Tuple[str | None] = ..., + ) -> Any: ... + @overload + def __call__( + self, + __x1: ArrayLike, + out: NDArray[Any] | tuple[NDArray[Any]] | None = ..., + *, + where: _ArrayLikeBool_co | None = ..., + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _2Tuple[str | None] = ..., + ) -> NDArray[Any]: ... + @overload + def __call__( + self, + __x1: _SupportsArrayUFunc, + out: NDArray[Any] | tuple[NDArray[Any]] | None = ..., + *, + where: _ArrayLikeBool_co | None = ..., + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _2Tuple[str | None] = ..., + ) -> Any: ... + + def at( + self, + a: _SupportsArrayUFunc, + indices: _ArrayLikeInt_co, + /, + ) -> None: ... + + def reduce(self, *args, **kwargs) -> NoReturn: ... + def accumulate(self, *args, **kwargs) -> NoReturn: ... + def reduceat(self, *args, **kwargs) -> NoReturn: ... + def outer(self, *args, **kwargs) -> NoReturn: ... + +@type_check_only +class _UFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc] + @property + def __name__(self) -> _NameType: ... + @property + def __qualname__(self) -> _NameType: ... + @property + def ntypes(self) -> _NTypes: ... + @property + def identity(self) -> _IDType: ... + @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 + def __call__( + self, + x1: _ScalarLike_co, + x2: _ScalarLike_co, + /, + out: None = None, + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> Any: ... + @overload # (array-like, array) -> array + def __call__( + self, + x1: ArrayLike, + x2: NDArray[np.generic], + /, + out: NDArray[np.generic] | tuple[NDArray[np.generic]] | None = None, + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> NDArray[Any]: ... + @overload # (array, array-like) -> array + def __call__( + self, + x1: NDArray[np.generic], + x2: ArrayLike, + /, + out: NDArray[np.generic] | tuple[NDArray[np.generic]] | None = None, + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> NDArray[Any]: ... + @overload # (array-like, array-like, out=array) -> array + def __call__( + self, + x1: ArrayLike, + x2: ArrayLike, + /, + out: NDArray[np.generic] | tuple[NDArray[np.generic]], + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> NDArray[Any]: ... + @overload # (array-like, array-like) -> array | scalar + def __call__( + self, + x1: ArrayLike, + x2: ArrayLike, + /, + out: NDArray[np.generic] | tuple[NDArray[np.generic]] | None = None, + *, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> NDArray[Any] | Any: ... + + def at( + self, + a: NDArray[Any], + indices: _ArrayLikeInt_co, + b: ArrayLike, + /, + ) -> None: ... + + def reduce( + self, + array: ArrayLike, + axis: _ShapeLike | None = ..., + dtype: DTypeLike = ..., + out: NDArray[Any] | None = ..., + keepdims: bool = ..., + initial: Any = ..., + where: _ArrayLikeBool_co = ..., + ) -> Any: ... + + def accumulate( + self, + array: ArrayLike, + axis: SupportsIndex = ..., + dtype: DTypeLike = ..., + out: NDArray[Any] | None = ..., + ) -> NDArray[Any]: ... + + def reduceat( + self, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex = ..., + dtype: DTypeLike = ..., + out: NDArray[Any] | None = ..., + ) -> NDArray[Any]: ... + + @overload # (scalar, scalar) -> scalar + def outer( + self, + A: _ScalarLike_co, + B: _ScalarLike_co, + /, + *, + out: None = None, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> Any: ... + @overload # (array-like, array) -> array + def outer( + self, + A: ArrayLike, + B: NDArray[np.generic], + /, + *, + out: NDArray[np.generic] | tuple[NDArray[np.generic]] | None = None, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> NDArray[Any]: ... + @overload # (array, array-like) -> array + def outer( + self, + A: NDArray[np.generic], + B: ArrayLike, + /, + *, + out: NDArray[np.generic] | tuple[NDArray[np.generic]] | None = None, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> NDArray[Any]: ... + @overload # (array-like, array-like, out=array) -> array + def outer( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + out: NDArray[np.generic] | tuple[NDArray[np.generic]], + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> NDArray[Any]: ... + @overload # (array-like, array-like) -> array | scalar + def outer( + self, + A: ArrayLike, + B: ArrayLike, + /, + *, + out: NDArray[np.generic] | tuple[NDArray[np.generic]] | None = None, + dtype: DTypeLike | None = None, + **kwds: Unpack[_UFunc3Kwargs], + ) -> NDArray[Any] | Any: ... + +@type_check_only +class _UFunc_Nin1_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc] + @property + def __name__(self) -> _NameType: ... + @property + def __qualname__(self) -> _NameType: ... + @property + def ntypes(self) -> _NTypes: ... + @property + def identity(self) -> _IDType: ... + @property + def nin(self) -> Literal[1]: ... + @property + def nout(self) -> Literal[2]: ... + @property + def nargs(self) -> Literal[3]: ... + @property + def signature(self) -> None: ... + + @overload + def __call__( + self, + __x1: _ScalarLike_co, + __out1: None = ..., + __out2: None = ..., + *, + where: _ArrayLikeBool_co | None = ..., + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _3Tuple[str | None] = ..., + ) -> _2Tuple[Any]: ... + @overload + def __call__( + self, + __x1: ArrayLike, + __out1: NDArray[Any] | None = ..., + __out2: NDArray[Any] | None = ..., + *, + out: _2Tuple[NDArray[Any]] = ..., + where: _ArrayLikeBool_co | None = ..., + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _3Tuple[str | None] = ..., + ) -> _2Tuple[NDArray[Any]]: ... + @overload + def __call__( + self, + __x1: _SupportsArrayUFunc, + __out1: NDArray[Any] | None = ..., + __out2: NDArray[Any] | None = ..., + *, + out: _2Tuple[NDArray[Any]] = ..., + where: _ArrayLikeBool_co | None = ..., + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _3Tuple[str | None] = ..., + ) -> _2Tuple[Any]: ... + + def at(self, *args, **kwargs) -> NoReturn: ... + def reduce(self, *args, **kwargs) -> NoReturn: ... + def accumulate(self, *args, **kwargs) -> NoReturn: ... + def reduceat(self, *args, **kwargs) -> NoReturn: ... + def outer(self, *args, **kwargs) -> NoReturn: ... + +@type_check_only +class _UFunc_Nin2_Nout2(ufunc, Generic[_NameType, _NTypes, _IDType]): # type: ignore[misc] + @property + def __name__(self) -> _NameType: ... + @property + def __qualname__(self) -> _NameType: ... + @property + def ntypes(self) -> _NTypes: ... + @property + def identity(self) -> _IDType: ... + @property + def nin(self) -> Literal[2]: ... + @property + def nout(self) -> Literal[2]: ... + @property + def nargs(self) -> Literal[4]: ... + @property + def signature(self) -> None: ... + + @overload + def __call__( + self, + __x1: _ScalarLike_co, + __x2: _ScalarLike_co, + __out1: None = ..., + __out2: None = ..., + *, + where: _ArrayLikeBool_co | None = ..., + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _4Tuple[str | None] = ..., + ) -> _2Tuple[Any]: ... + @overload + def __call__( + self, + __x1: ArrayLike, + __x2: ArrayLike, + __out1: NDArray[Any] | None = ..., + __out2: NDArray[Any] | None = ..., + *, + out: _2Tuple[NDArray[Any]] = ..., + where: _ArrayLikeBool_co | None = ..., + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _4Tuple[str | None] = ..., + ) -> _2Tuple[NDArray[Any]]: ... + + def at(self, *args, **kwargs) -> NoReturn: ... + def reduce(self, *args, **kwargs) -> NoReturn: ... + def accumulate(self, *args, **kwargs) -> NoReturn: ... + def reduceat(self, *args, **kwargs) -> NoReturn: ... + def outer(self, *args, **kwargs) -> NoReturn: ... + +@type_check_only +class _GUFunc_Nin2_Nout1(ufunc, Generic[_NameType, _NTypes, _IDType, _Signature]): # type: ignore[misc] + @property + def __name__(self) -> _NameType: ... + @property + def __qualname__(self) -> _NameType: ... + @property + def ntypes(self) -> _NTypes: ... + @property + def identity(self) -> _IDType: ... + @property + def nin(self) -> Literal[2]: ... + @property + def nout(self) -> Literal[1]: ... + @property + def nargs(self) -> Literal[3]: ... + @property + def signature(self) -> _Signature: ... + + # Scalar for 1D array-likes; ndarray otherwise + @overload + def __call__( + self, + __x1: ArrayLike, + __x2: ArrayLike, + out: None = ..., + *, + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _3Tuple[str | None] = ..., + axes: list[_2Tuple[SupportsIndex]] = ..., + ) -> Any: ... + @overload + def __call__( + self, + __x1: ArrayLike, + __x2: ArrayLike, + out: NDArray[Any] | tuple[NDArray[Any]], + *, + casting: _CastingKind = ..., + order: _OrderKACF = ..., + dtype: DTypeLike = ..., + subok: bool = ..., + signature: str | _3Tuple[str | None] = ..., + axes: list[_2Tuple[SupportsIndex]] = ..., + ) -> NDArray[Any]: ... + + def at(self, *args, **kwargs) -> NoReturn: ... + def reduce(self, *args, **kwargs) -> NoReturn: ... + def accumulate(self, *args, **kwargs) -> NoReturn: ... + def reduceat(self, *args, **kwargs) -> NoReturn: ... + def outer(self, *args, **kwargs) -> NoReturn: ... + +@type_check_only +class _PyFunc_Kwargs_Nargs2(TypedDict, total=False): + where: _ArrayLikeBool_co | None + casting: _CastingKind + order: _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: _CastingKind + order: _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: _CastingKind + order: _OrderKACF + dtype: DTypeLike + subok: bool + signature: str | _3PTuple[DTypeLike] + +@type_check_only +class _PyFunc_Kwargs_Nargs4P(TypedDict, total=False): + where: _ArrayLikeBool_co | None + casting: _CastingKind + order: _OrderKACF + dtype: DTypeLike + subok: bool + signature: str | _4PTuple[DTypeLike] + +@type_check_only +class _PyFunc_Nin1_Nout1(ufunc, Generic[_ReturnType_co, _IDType]): # type: ignore[misc] + @property + def identity(self) -> _IDType: ... + @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: ... + + @overload + def __call__( + self, + x1: _ScalarLike_co, + /, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs2], + ) -> _ReturnType_co: ... + @overload + def __call__( + self, + x1: ArrayLike, + /, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs2], + ) -> _ReturnType_co | NDArray[np.object_]: ... + @overload + def __call__( + self, + x1: ArrayLike, + /, + out: _ArrayT | tuple[_ArrayT], + **kwargs: Unpack[_PyFunc_Kwargs_Nargs2], + ) -> _ArrayT: ... + @overload + def __call__( + self, + x1: _SupportsArrayUFunc, + /, + out: NDArray[Any] | tuple[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(ufunc, Generic[_ReturnType_co, _IDType]): # type: ignore[misc] + @property + def identity(self) -> _IDType: ... + @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: ... + + @overload + def __call__( + self, + x1: _ScalarLike_co, + x2: _ScalarLike_co, + /, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> _ReturnType_co: ... + @overload + def __call__( + self, + x1: ArrayLike, + x2: ArrayLike, + /, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> _ReturnType_co | NDArray[np.object_]: ... + @overload + def __call__( + self, + x1: ArrayLike, + x2: ArrayLike, + /, + out: _ArrayT | tuple[_ArrayT], + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> _ArrayT: ... + @overload + def __call__( + self, + x1: _SupportsArrayUFunc, + x2: _SupportsArrayUFunc | ArrayLike, + /, + out: NDArray[Any] | tuple[NDArray[Any]] | None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> Any: ... + @overload + def __call__( + self, + x1: ArrayLike, + x2: _SupportsArrayUFunc, + /, + out: NDArray[Any] | tuple[NDArray[Any]] | None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> Any: ... + + def at(self, a: _SupportsArrayUFunc, ixs: _ArrayLikeInt_co, b: ArrayLike, /) -> None: ... + + @overload + def reduce( + self, + array: ArrayLike, + axis: _ShapeLike | None, + dtype: DTypeLike, + out: _ArrayT, + /, + keepdims: bool = ..., + initial: _ScalarLike_co = ..., + where: _ArrayLikeBool_co = ..., + ) -> _ArrayT: ... + @overload + def reduce( + self, + /, + array: ArrayLike, + axis: _ShapeLike | None = ..., + dtype: DTypeLike = ..., + *, + out: _ArrayT | tuple[_ArrayT], + keepdims: bool = ..., + initial: _ScalarLike_co = ..., + where: _ArrayLikeBool_co = ..., + ) -> _ArrayT: ... + @overload + def reduce( + self, + /, + array: ArrayLike, + axis: _ShapeLike | None = ..., + dtype: DTypeLike = ..., + out: None = ..., + *, + keepdims: Literal[True], + initial: _ScalarLike_co = ..., + where: _ArrayLikeBool_co = ..., + ) -> NDArray[np.object_]: ... + @overload + def reduce( + self, + /, + array: ArrayLike, + axis: _ShapeLike | None = ..., + dtype: DTypeLike = ..., + out: None = ..., + keepdims: bool = ..., + initial: _ScalarLike_co = ..., + where: _ArrayLikeBool_co = ..., + ) -> _ReturnType_co | NDArray[np.object_]: ... + + @overload + def reduceat( + self, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex, + dtype: DTypeLike, + out: _ArrayT, + /, + ) -> _ArrayT: ... + @overload + def reduceat( + self, + /, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex = ..., + dtype: DTypeLike = ..., + *, + out: _ArrayT | tuple[_ArrayT], + ) -> _ArrayT: ... + @overload + def reduceat( + self, + /, + array: ArrayLike, + indices: _ArrayLikeInt_co, + axis: SupportsIndex = ..., + dtype: DTypeLike = ..., + out: None = ..., + ) -> NDArray[np.object_]: ... + @overload + def reduceat( + self, + /, + array: _SupportsArrayUFunc, + indices: _ArrayLikeInt_co, + axis: SupportsIndex = ..., + dtype: DTypeLike = ..., + out: NDArray[Any] | tuple[NDArray[Any]] | None = ..., + ) -> Any: ... + + @overload + def accumulate( + self, + array: ArrayLike, + axis: SupportsIndex, + dtype: DTypeLike, + out: _ArrayT, + /, + ) -> _ArrayT: ... + @overload + def accumulate( + self, + array: ArrayLike, + axis: SupportsIndex = ..., + dtype: DTypeLike = ..., + *, + out: _ArrayT | tuple[_ArrayT], + ) -> _ArrayT: ... + @overload + def accumulate( + self, + /, + array: ArrayLike, + axis: SupportsIndex = ..., + dtype: DTypeLike = ..., + out: None = ..., + ) -> NDArray[np.object_]: ... + + @overload + def outer( + self, + A: _ScalarLike_co, + B: _ScalarLike_co, + /, *, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> _ReturnType_co: ... + @overload + def outer( + self, + A: ArrayLike, + B: ArrayLike, + /, *, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> _ReturnType_co | NDArray[np.object_]: ... + @overload + def outer( + self, + A: ArrayLike, + B: ArrayLike, + /, *, + out: _ArrayT, + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> _ArrayT: ... + @overload + def outer( + self, + A: _SupportsArrayUFunc, + B: _SupportsArrayUFunc | ArrayLike, + /, *, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> Any: ... + @overload + def outer( + self, + A: _ScalarLike_co, + B: _SupportsArrayUFunc | ArrayLike, + /, *, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3], + ) -> Any: ... + +@type_check_only +class _PyFunc_Nin3P_Nout1(ufunc, Generic[_ReturnType_co, _IDType, _NIn]): # type: ignore[misc] + @property + def identity(self) -> _IDType: ... + @property + def nin(self) -> _NIn: ... + @property + def nout(self) -> Literal[1]: ... + @property + def ntypes(self) -> Literal[1]: ... + @property + def signature(self) -> None: ... + + @overload + def __call__( + self, + x1: _ScalarLike_co, + x2: _ScalarLike_co, + x3: _ScalarLike_co, + /, + *xs: _ScalarLike_co, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P], + ) -> _ReturnType_co: ... + @overload + def __call__( + self, + x1: ArrayLike, + x2: ArrayLike, + x3: ArrayLike, + /, + *xs: ArrayLike, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P], + ) -> _ReturnType_co | NDArray[np.object_]: ... + @overload + def __call__( + self, + x1: ArrayLike, + x2: ArrayLike, + x3: ArrayLike, + /, + *xs: ArrayLike, + out: _ArrayT | tuple[_ArrayT], + **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P], + ) -> _ArrayT: ... + @overload + def __call__( + self, + x1: _SupportsArrayUFunc | ArrayLike, + x2: _SupportsArrayUFunc | ArrayLike, + x3: _SupportsArrayUFunc | ArrayLike, + /, + *xs: _SupportsArrayUFunc | ArrayLike, + out: NDArray[Any] | tuple[NDArray[Any]] | None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs4P], + ) -> 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(ufunc, Generic[_ReturnType_co, _IDType, _NIn, _NOut]): # type: ignore[misc] + @property + def identity(self) -> _IDType: ... + @property + def nin(self) -> _NIn: ... + @property + def nout(self) -> _NOut: ... + @property + def ntypes(self) -> Literal[1]: ... + @property + def signature(self) -> None: ... + + @overload + def __call__( + self, + x1: _ScalarLike_co, + /, + *xs: _ScalarLike_co, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], + ) -> _2PTuple[_ReturnType_co]: ... + @overload + def __call__( + self, + x1: ArrayLike, + /, + *xs: ArrayLike, + out: None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], + ) -> _2PTuple[_ReturnType_co | NDArray[np.object_]]: ... + @overload + def __call__( + self, + x1: ArrayLike, + /, + *xs: ArrayLike, + out: _2PTuple[_ArrayT], + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], + ) -> _2PTuple[_ArrayT]: ... + @overload + def __call__( + self, + x1: _SupportsArrayUFunc | ArrayLike, + /, + *xs: _SupportsArrayUFunc | ArrayLike, + out: _2PTuple[NDArray[Any]] | None = ..., + **kwargs: Unpack[_PyFunc_Kwargs_Nargs3P], + ) -> 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: ... |
