summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/__init__.pyi978
-rw-r--r--numpy/core/_add_newdocs.py4
-rw-r--r--numpy/core/fromnumeric.py12
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h2
-rw-r--r--numpy/core/src/common/simd/avx2/math.h2
-rw-r--r--numpy/core/src/common/simd/avx512/math.h2
-rw-r--r--numpy/core/src/common/simd/neon/math.h2
-rw-r--r--numpy/core/src/common/simd/sse/math.h2
-rw-r--r--numpy/core/src/multiarray/_multiarray_tests.c.src17
-rw-r--r--numpy/core/src/multiarray/array_coercion.c8
-rw-r--r--numpy/core/src/multiarray/ctors.c127
-rw-r--r--numpy/core/src/multiarray/iterators.c3
-rw-r--r--numpy/core/src/multiarray/nditer_constr.c6
-rw-r--r--numpy/core/src/umath/_umath_tests.c.src2
-rw-r--r--numpy/core/src/umath/ufunc_object.c9
-rw-r--r--numpy/core/src/umath/ufunc_type_resolution.c251
-rw-r--r--numpy/core/src/umath/ufunc_type_resolution.h1
-rw-r--r--numpy/core/tests/test_deprecations.py5
-rw-r--r--numpy/core/tests/test_multiarray.py17
-rw-r--r--numpy/core/tests/test_regression.py16
-rw-r--r--numpy/core/tests/test_scalar_methods.py3
-rw-r--r--numpy/core/tests/test_ufunc.py28
-rw-r--r--numpy/lib/index_tricks.pyi30
-rw-r--r--numpy/lib/ufunclike.pyi10
-rw-r--r--numpy/ma/tests/test_mrecords.py2
-rw-r--r--numpy/typing/__init__.py5
-rw-r--r--numpy/typing/_add_docstring.py51
-rw-r--r--numpy/typing/_array_like.py5
-rw-r--r--numpy/typing/_callable.py5
-rw-r--r--numpy/typing/_generic_alias.py207
-rw-r--r--numpy/typing/tests/data/fail/datasource.py15
-rw-r--r--numpy/typing/tests/data/fail/ndarray_misc.py9
-rw-r--r--numpy/typing/tests/data/pass/multiarray.py37
-rw-r--r--numpy/typing/tests/data/pass/ndarray_misc.py21
-rw-r--r--numpy/typing/tests/data/pass/scalars.py62
-rw-r--r--numpy/typing/tests/data/reveal/datasource.py21
-rw-r--r--numpy/typing/tests/data/reveal/multiarray.py35
-rw-r--r--numpy/typing/tests/data/reveal/ndarray_misc.py34
-rw-r--r--numpy/typing/tests/data/reveal/scalars.py93
-rw-r--r--numpy/typing/tests/test_generic_alias.py112
40 files changed, 1553 insertions, 698 deletions
diff --git a/numpy/__init__.pyi b/numpy/__init__.pyi
index b708b99ab..2d23f926d 100644
--- a/numpy/__init__.pyi
+++ b/numpy/__init__.pyi
@@ -10,7 +10,7 @@ from numpy.core._internal import _ctypes
from numpy.typing import (
# Arrays
ArrayLike,
- _ArrayND,
+ NDArray,
_SupportsArray,
_NestedSequence,
_RecursiveSequence,
@@ -42,6 +42,7 @@ from numpy.typing import (
_ComplexLike_co,
_TD64Like_co,
_NumberLike_co,
+ _ScalarLike_co,
# `number` precision
NBitBase,
@@ -558,13 +559,6 @@ __git_version__: str
#
# Placeholders for classes
# TODO: Remove `__getattr__` once the classes are stubbed out
-class DataSource:
- def __init__(self, destpath: Any = ...) -> None: ...
- def __del__(self): ...
- def abspath(self, path): ...
- def exists(self, path): ...
- def open(self, path, mode=..., encoding=..., newline=...): ...
-
class MachAr:
def __init__(
self,
@@ -576,10 +570,6 @@ class MachAr:
) -> None: ...
def __getattr__(self, key: str) -> Any: ...
-class broadcast:
- def __new__(cls: Any, *args: Any) -> Any: ...
- def __getattr__(self, key: str) -> Any: ...
-
class busdaycalendar:
def __new__(cls, weekmask: Any = ..., holidays: Any = ...) -> Any: ...
def __getattr__(self, key: str) -> Any: ...
@@ -1239,19 +1229,9 @@ class _ArrayOrScalarCommon:
def copy(self: _ArraySelf, order: _OrderKACF = ...) -> _ArraySelf: ...
def dump(self, file: str) -> None: ...
def dumps(self) -> bytes: ...
- def flatten(self, order: _OrderKACF = ...) -> ndarray: ...
def getfield(
self: _ArraySelf, dtype: DTypeLike, offset: int = ...
) -> _ArraySelf: ...
- def ravel(self, order: _OrderKACF = ...) -> ndarray: ...
- @overload
- def reshape(
- self, __shape: _ShapeLike, *, order: _OrderACF = ...
- ) -> ndarray: ...
- @overload
- def reshape(
- self, *shape: SupportsIndex, order: _OrderACF = ...
- ) -> ndarray: ...
def tobytes(self, order: _OrderKACF = ...) -> bytes: ...
# NOTE: `tostring()` is deprecated and therefore excluded
# def tostring(self, order=...): ...
@@ -1649,12 +1629,12 @@ _T_co = TypeVar("_T_co", covariant=True)
_2Tuple = Tuple[_T, _T]
_Casting = Literal["no", "equiv", "safe", "same_kind", "unsafe"]
-_ArrayUInt_co = _ArrayND[Union[bool_, unsignedinteger[Any]]]
-_ArrayInt_co = _ArrayND[Union[bool_, integer[Any]]]
-_ArrayFloat_co = _ArrayND[Union[bool_, integer[Any], floating[Any]]]
-_ArrayComplex_co = _ArrayND[Union[bool_, integer[Any], floating[Any], complexfloating[Any, Any]]]
-_ArrayNumber_co = _ArrayND[Union[bool_, number[Any]]]
-_ArrayTD64_co = _ArrayND[Union[bool_, integer[Any], timedelta64]]
+_ArrayUInt_co = NDArray[Union[bool_, unsignedinteger[Any]]]
+_ArrayInt_co = NDArray[Union[bool_, integer[Any]]]
+_ArrayFloat_co = NDArray[Union[bool_, integer[Any], floating[Any]]]
+_ArrayComplex_co = NDArray[Union[bool_, integer[Any], floating[Any], complexfloating[Any, Any]]]
+_ArrayNumber_co = NDArray[Union[bool_, number[Any]]]
+_ArrayTD64_co = NDArray[Union[bool_, integer[Any], timedelta64]]
class _SupportsItem(Protocol[_T_co]):
def item(self, __args: Any) -> _T_co: ...
@@ -1718,40 +1698,59 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
def itemset(self, __value: Any) -> None: ...
@overload
def itemset(self, __item: _ShapeLike, __value: Any) -> None: ...
+
@overload
def resize(self, __new_shape: _ShapeLike, *, refcheck: bool = ...) -> None: ...
@overload
def resize(self, *new_shape: SupportsIndex, refcheck: bool = ...) -> None: ...
+
def setflags(
self, write: bool = ..., align: bool = ..., uic: bool = ...
) -> None: ...
+
def squeeze(
- self: _ArraySelf, axis: Union[SupportsIndex, Tuple[SupportsIndex, ...]] = ...
- ) -> _ArraySelf: ...
- def swapaxes(self: _ArraySelf, axis1: SupportsIndex, axis2: SupportsIndex) -> _ArraySelf: ...
+ self,
+ axis: Union[SupportsIndex, Tuple[SupportsIndex, ...]] = ...,
+ ) -> ndarray[Any, _DType_co]: ...
+
+ def swapaxes(
+ self,
+ axis1: SupportsIndex,
+ axis2: SupportsIndex,
+ ) -> ndarray[Any, _DType_co]: ...
+
@overload
def transpose(self: _ArraySelf, __axes: _ShapeLike) -> _ArraySelf: ...
@overload
def transpose(self: _ArraySelf, *axes: SupportsIndex) -> _ArraySelf: ...
+
def argpartition(
self,
kth: _ArrayLikeInt_co,
axis: Optional[SupportsIndex] = ...,
kind: _PartitionKind = ...,
order: Union[None, str, Sequence[str]] = ...,
- ) -> ndarray: ...
+ ) -> ndarray[Any, dtype[intp]]: ...
+
def diagonal(
- self: _ArraySelf,
+ self,
offset: SupportsIndex = ...,
axis1: SupportsIndex = ...,
axis2: SupportsIndex = ...,
- ) -> _ArraySelf: ...
+ ) -> ndarray[Any, _DType_co]: ...
+
+ # 1D + 1D returns a scalar;
+ # all other with at least 1 non-0D array return an ndarray.
+ @overload
+ def dot(self, b: _ScalarLike_co, out: None = ...) -> ndarray: ...
@overload
- def dot(self, b: ArrayLike, out: None = ...) -> ndarray: ...
+ def dot(self, b: ArrayLike, out: None = ...) -> Any: ... # type: ignore[misc]
@overload
- def dot(self, b: ArrayLike, out: _NdArraySubClass = ...) -> _NdArraySubClass: ...
+ def dot(self, b: ArrayLike, out: _NdArraySubClass) -> _NdArraySubClass: ...
+
# `nonzero()` is deprecated for 0d arrays/generics
- def nonzero(self) -> Tuple[ndarray, ...]: ...
+ def nonzero(self) -> Tuple[ndarray[Any, dtype[intp]], ...]: ...
+
def partition(
self,
kth: _ArrayLikeInt_co,
@@ -1759,26 +1758,45 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
kind: _PartitionKind = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> None: ...
+
# `put` is technically available to `generic`,
# but is pointless as `generic`s are immutable
def put(
- self, ind: _ArrayLikeInt_co, v: ArrayLike, mode: _ModeKind = ...
+ self,
+ ind: _ArrayLikeInt_co,
+ v: ArrayLike,
+ mode: _ModeKind = ...,
) -> None: ...
+
+ @overload
+ def searchsorted( # type: ignore[misc]
+ self, # >= 1D array
+ v: _ScalarLike_co, # 0D array-like
+ side: _SortSide = ...,
+ sorter: Optional[_ArrayLikeInt_co] = ...,
+ ) -> intp: ...
+ @overload
def searchsorted(
self, # >= 1D array
v: ArrayLike,
side: _SortSide = ...,
- sorter: Optional[_ArrayLikeInt_co] = ..., # 1D int array
- ) -> ndarray: ...
+ sorter: Optional[_ArrayLikeInt_co] = ...,
+ ) -> ndarray[Any, dtype[intp]]: ...
+
def setfield(
- self, val: ArrayLike, dtype: DTypeLike, offset: SupportsIndex = ...
+ self,
+ val: ArrayLike,
+ dtype: DTypeLike,
+ offset: SupportsIndex = ...,
) -> None: ...
+
def sort(
self,
axis: SupportsIndex = ...,
kind: Optional[_SortKind] = ...,
order: Union[None, str, Sequence[str]] = ...,
) -> None: ...
+
@overload
def trace(
self, # >= 2D array
@@ -1829,17 +1847,46 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
axis: Optional[SupportsIndex] = ...,
) -> ndarray[Any, _DType_co]: ...
- # Many of these special methods are irrelevant currently, since protocols
- # aren't supported yet. That said, I'm adding them for completeness.
- # https://docs.python.org/3/reference/datamodel.html
- def __int__(self) -> int: ...
- def __float__(self) -> float: ...
- def __complex__(self) -> complex: ...
+ def flatten(
+ self,
+ order: _OrderKACF = ...,
+ ) -> ndarray[Any, _DType_co]: ...
+
+ def ravel(
+ self,
+ order: _OrderKACF = ...,
+ ) -> ndarray[Any, _DType_co]: ...
+
+ @overload
+ def reshape(
+ self, __shape: _ShapeLike, *, order: _OrderACF = ...
+ ) -> ndarray[Any, _DType_co]: ...
+ @overload
+ def reshape(
+ self, *shape: SupportsIndex, order: _OrderACF = ...
+ ) -> ndarray[Any, _DType_co]: ...
+
+ # Dispatch to the underlying `generic` via protocols
+ def __int__(
+ self: ndarray[Any, dtype[SupportsInt]], # type: ignore[type-var]
+ ) -> int: ...
+
+ def __float__(
+ self: ndarray[Any, dtype[SupportsFloat]], # type: ignore[type-var]
+ ) -> float: ...
+
+ def __complex__(
+ self: ndarray[Any, dtype[SupportsComplex]], # type: ignore[type-var]
+ ) -> complex: ...
+
+ def __index__(
+ self: ndarray[Any, dtype[SupportsIndex]], # type: ignore[type-var]
+ ) -> int: ...
+
def __len__(self) -> int: ...
def __setitem__(self, key, value): ...
def __iter__(self) -> Any: ...
def __contains__(self, key) -> bool: ...
- def __index__(self) -> int: ...
# The last overload is for catching recursive objects whose
# nesting is too deep.
@@ -1848,128 +1895,128 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
# strings, it will pass through the final overload otherwise
@overload
- def __lt__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __lt__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __lt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> _ArrayND[bool_]: ...
+ def __lt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> NDArray[bool_]: ...
@overload
- def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> _ArrayND[bool_]: ...
+ def __lt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[bool_]: ...
@overload
- def __lt__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayND[bool_]: ...
+ def __lt__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[bool_]: ...
@overload
- def __lt__(self: _ArrayND[object_], other: Any) -> _ArrayND[bool_]: ...
+ def __lt__(self: NDArray[object_], other: Any) -> NDArray[bool_]: ...
@overload
- def __lt__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> _ArrayND[bool_]: ...
+ def __lt__(self: NDArray[Any], other: _ArrayLikeObject_co) -> NDArray[bool_]: ...
@overload
def __lt__(
- self: _ArrayND[Union[number[Any], datetime64, timedelta64, bool_]],
+ self: NDArray[Union[number[Any], datetime64, timedelta64, bool_]],
other: _RecursiveSequence,
- ) -> _ArrayND[bool_]: ...
+ ) -> NDArray[bool_]: ...
@overload
- def __le__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __le__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __le__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> _ArrayND[bool_]: ...
+ def __le__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> NDArray[bool_]: ...
@overload
- def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> _ArrayND[bool_]: ...
+ def __le__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[bool_]: ...
@overload
- def __le__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayND[bool_]: ...
+ def __le__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[bool_]: ...
@overload
- def __le__(self: _ArrayND[object_], other: Any) -> _ArrayND[bool_]: ...
+ def __le__(self: NDArray[object_], other: Any) -> NDArray[bool_]: ...
@overload
- def __le__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> _ArrayND[bool_]: ...
+ def __le__(self: NDArray[Any], other: _ArrayLikeObject_co) -> NDArray[bool_]: ...
@overload
def __le__(
- self: _ArrayND[Union[number[Any], datetime64, timedelta64, bool_]],
+ self: NDArray[Union[number[Any], datetime64, timedelta64, bool_]],
other: _RecursiveSequence,
- ) -> _ArrayND[bool_]: ...
+ ) -> NDArray[bool_]: ...
@overload
- def __gt__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __gt__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __gt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> _ArrayND[bool_]: ...
+ def __gt__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> NDArray[bool_]: ...
@overload
- def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> _ArrayND[bool_]: ...
+ def __gt__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[bool_]: ...
@overload
- def __gt__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayND[bool_]: ...
+ def __gt__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[bool_]: ...
@overload
- def __gt__(self: _ArrayND[object_], other: Any) -> _ArrayND[bool_]: ...
+ def __gt__(self: NDArray[object_], other: Any) -> NDArray[bool_]: ...
@overload
- def __gt__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> _ArrayND[bool_]: ...
+ def __gt__(self: NDArray[Any], other: _ArrayLikeObject_co) -> NDArray[bool_]: ...
@overload
def __gt__(
- self: _ArrayND[Union[number[Any], datetime64, timedelta64, bool_]],
+ self: NDArray[Union[number[Any], datetime64, timedelta64, bool_]],
other: _RecursiveSequence,
- ) -> _ArrayND[bool_]: ...
+ ) -> NDArray[bool_]: ...
@overload
- def __ge__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __ge__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __ge__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> _ArrayND[bool_]: ...
+ def __ge__(self: _ArrayNumber_co, other: _ArrayLikeNumber_co) -> NDArray[bool_]: ...
@overload
- def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> _ArrayND[bool_]: ...
+ def __ge__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[bool_]: ...
@overload
- def __ge__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayND[bool_]: ...
+ def __ge__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[bool_]: ...
@overload
- def __ge__(self: _ArrayND[object_], other: Any) -> _ArrayND[bool_]: ...
+ def __ge__(self: NDArray[object_], other: Any) -> NDArray[bool_]: ...
@overload
- def __ge__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> _ArrayND[bool_]: ...
+ def __ge__(self: NDArray[Any], other: _ArrayLikeObject_co) -> NDArray[bool_]: ...
@overload
def __ge__(
- self: _ArrayND[Union[number[Any], datetime64, timedelta64, bool_]],
+ self: NDArray[Union[number[Any], datetime64, timedelta64, bool_]],
other: _RecursiveSequence,
- ) -> _ArrayND[bool_]: ...
+ ) -> NDArray[bool_]: ...
# Unary ops
@overload
- def __abs__(self: _ArrayND[bool_]) -> _ArrayND[bool_]: ...
+ def __abs__(self: NDArray[bool_]) -> NDArray[bool_]: ...
@overload
- def __abs__(self: _ArrayND[complexfloating[_NBit1, _NBit1]]) -> _ArrayND[floating[_NBit1]]: ...
+ def __abs__(self: NDArray[complexfloating[_NBit1, _NBit1]]) -> NDArray[floating[_NBit1]]: ...
@overload
- def __abs__(self: _ArrayND[_NumberType]) -> _ArrayND[_NumberType]: ...
+ def __abs__(self: NDArray[_NumberType]) -> NDArray[_NumberType]: ...
@overload
- def __abs__(self: _ArrayND[timedelta64]) -> _ArrayND[timedelta64]: ...
+ def __abs__(self: NDArray[timedelta64]) -> NDArray[timedelta64]: ...
@overload
- def __abs__(self: _ArrayND[object_]) -> Any: ...
+ def __abs__(self: NDArray[object_]) -> Any: ...
@overload
- def __invert__(self: _ArrayND[bool_]) -> _ArrayND[bool_]: ...
+ def __invert__(self: NDArray[bool_]) -> NDArray[bool_]: ...
@overload
- def __invert__(self: _ArrayND[_IntType]) -> _ArrayND[_IntType]: ...
+ def __invert__(self: NDArray[_IntType]) -> NDArray[_IntType]: ...
@overload
- def __invert__(self: _ArrayND[object_]) -> Any: ...
+ def __invert__(self: NDArray[object_]) -> Any: ...
@overload
- def __pos__(self: _ArrayND[_NumberType]) -> _ArrayND[_NumberType]: ...
+ def __pos__(self: NDArray[_NumberType]) -> NDArray[_NumberType]: ...
@overload
- def __pos__(self: _ArrayND[timedelta64]) -> _ArrayND[timedelta64]: ...
+ def __pos__(self: NDArray[timedelta64]) -> NDArray[timedelta64]: ...
@overload
- def __pos__(self: _ArrayND[object_]) -> Any: ...
+ def __pos__(self: NDArray[object_]) -> Any: ...
@overload
- def __neg__(self: _ArrayND[_NumberType]) -> _ArrayND[_NumberType]: ...
+ def __neg__(self: NDArray[_NumberType]) -> NDArray[_NumberType]: ...
@overload
- def __neg__(self: _ArrayND[timedelta64]) -> _ArrayND[timedelta64]: ...
+ def __neg__(self: NDArray[timedelta64]) -> NDArray[timedelta64]: ...
@overload
- def __neg__(self: _ArrayND[object_]) -> Any: ...
+ def __neg__(self: NDArray[object_]) -> Any: ...
# Binary ops
# NOTE: `ndarray` does not implement `__imatmul__`
@overload
- def __matmul__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __matmul__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __matmul__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __matmul__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __matmul__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __matmul__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __matmul__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __matmul__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __matmul__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __matmul__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __matmul__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ...
+ def __matmul__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ...
@overload
- def __matmul__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __matmul__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __matmul__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __matmul__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __matmul__(
self: _ArrayNumber_co,
@@ -1977,21 +2024,21 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
) -> Any: ...
@overload
- def __rmatmul__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rmatmul__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rmatmul__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __rmatmul__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __rmatmul__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rmatmul__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rmatmul__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __rmatmul__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rmatmul__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __rmatmul__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __rmatmul__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ...
+ def __rmatmul__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ...
@overload
- def __rmatmul__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rmatmul__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rmatmul__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rmatmul__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rmatmul__(
self: _ArrayNumber_co,
@@ -1999,761 +2046,761 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
) -> Any: ...
@overload
- def __mod__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __mod__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __mod__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __mod__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __mod__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __mod__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __mod__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __mod__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __mod__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __mod__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __mod__(self: _ArrayTD64_co, other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[timedelta64]: ...
+ def __mod__(self: _ArrayTD64_co, other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> NDArray[timedelta64]: ...
@overload
- def __mod__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __mod__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __mod__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __mod__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __mod__(
- self: _ArrayND[Union[bool_, integer[Any], floating[Any], timedelta64]],
+ self: NDArray[Union[bool_, integer[Any], floating[Any], timedelta64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rmod__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rmod__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rmod__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __rmod__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __rmod__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rmod__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rmod__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __rmod__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rmod__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __rmod__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __rmod__(self: _ArrayTD64_co, other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[timedelta64]: ...
+ def __rmod__(self: _ArrayTD64_co, other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> NDArray[timedelta64]: ...
@overload
- def __rmod__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rmod__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rmod__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rmod__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rmod__(
- self: _ArrayND[Union[bool_, integer[Any], floating[Any], timedelta64]],
+ self: NDArray[Union[bool_, integer[Any], floating[Any], timedelta64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __divmod__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __divmod__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __divmod__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _2Tuple[_ArrayND[int8]]: ... # type: ignore[misc]
+ def __divmod__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> _2Tuple[NDArray[int8]]: ... # type: ignore[misc]
@overload
- def __divmod__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _2Tuple[_ArrayND[unsignedinteger[Any]]]: ... # type: ignore[misc]
+ def __divmod__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _2Tuple[NDArray[unsignedinteger[Any]]]: ... # type: ignore[misc]
@overload
- def __divmod__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _2Tuple[_ArrayND[signedinteger[Any]]]: ... # type: ignore[misc]
+ def __divmod__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _2Tuple[NDArray[signedinteger[Any]]]: ... # type: ignore[misc]
@overload
- def __divmod__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _2Tuple[_ArrayND[floating[Any]]]: ... # type: ignore[misc]
+ def __divmod__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _2Tuple[NDArray[floating[Any]]]: ... # type: ignore[misc]
@overload
- def __divmod__(self: _ArrayTD64_co, other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> Tuple[_ArrayND[int64], _ArrayND[timedelta64]]: ...
+ def __divmod__(self: _ArrayTD64_co, other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> Tuple[NDArray[int64], NDArray[timedelta64]]: ...
@overload
def __divmod__(
- self: _ArrayND[Union[bool_, integer[Any], floating[Any], timedelta64]],
+ self: NDArray[Union[bool_, integer[Any], floating[Any], timedelta64]],
other: _RecursiveSequence,
) -> _2Tuple[Any]: ...
@overload
- def __rdivmod__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rdivmod__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rdivmod__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _2Tuple[_ArrayND[int8]]: ... # type: ignore[misc]
+ def __rdivmod__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> _2Tuple[NDArray[int8]]: ... # type: ignore[misc]
@overload
- def __rdivmod__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _2Tuple[_ArrayND[unsignedinteger[Any]]]: ... # type: ignore[misc]
+ def __rdivmod__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _2Tuple[NDArray[unsignedinteger[Any]]]: ... # type: ignore[misc]
@overload
- def __rdivmod__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _2Tuple[_ArrayND[signedinteger[Any]]]: ... # type: ignore[misc]
+ def __rdivmod__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _2Tuple[NDArray[signedinteger[Any]]]: ... # type: ignore[misc]
@overload
- def __rdivmod__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _2Tuple[_ArrayND[floating[Any]]]: ... # type: ignore[misc]
+ def __rdivmod__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _2Tuple[NDArray[floating[Any]]]: ... # type: ignore[misc]
@overload
- def __rdivmod__(self: _ArrayTD64_co, other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> Tuple[_ArrayND[int64], _ArrayND[timedelta64]]: ...
+ def __rdivmod__(self: _ArrayTD64_co, other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> Tuple[NDArray[int64], NDArray[timedelta64]]: ...
@overload
def __rdivmod__(
- self: _ArrayND[Union[bool_, integer[Any], floating[Any], timedelta64]],
+ self: NDArray[Union[bool_, integer[Any], floating[Any], timedelta64]],
other: _RecursiveSequence,
) -> _2Tuple[Any]: ...
@overload
- def __add__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __add__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __add__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __add__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __add__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __add__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __add__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __add__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __add__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __add__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __add__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __add__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __add__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ... # type: ignore[misc]
+ def __add__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ... # type: ignore[misc]
@overload
- def __add__(self: _ArrayTD64_co, other: _ArrayLikeDT64_co) -> _ArrayND[datetime64]: ...
+ def __add__(self: _ArrayTD64_co, other: _ArrayLikeDT64_co) -> NDArray[datetime64]: ...
@overload
- def __add__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ...
+ def __add__(self: NDArray[datetime64], other: _ArrayLikeTD64_co) -> NDArray[datetime64]: ...
@overload
- def __add__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __add__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __add__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __add__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __add__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64, datetime64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64, datetime64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __radd__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __radd__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __radd__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __radd__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __radd__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __radd__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __radd__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __radd__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __radd__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __radd__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __radd__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __radd__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __radd__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ... # type: ignore[misc]
+ def __radd__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ... # type: ignore[misc]
@overload
- def __radd__(self: _ArrayTD64_co, other: _ArrayLikeDT64_co) -> _ArrayND[datetime64]: ...
+ def __radd__(self: _ArrayTD64_co, other: _ArrayLikeDT64_co) -> NDArray[datetime64]: ...
@overload
- def __radd__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ...
+ def __radd__(self: NDArray[datetime64], other: _ArrayLikeTD64_co) -> NDArray[datetime64]: ...
@overload
- def __radd__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __radd__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __radd__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __radd__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __radd__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64, datetime64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64, datetime64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __sub__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __sub__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __sub__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> NoReturn: ...
+ def __sub__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
- def __sub__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __sub__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __sub__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __sub__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __sub__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __sub__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __sub__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __sub__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __sub__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ... # type: ignore[misc]
+ def __sub__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ... # type: ignore[misc]
@overload
- def __sub__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ...
+ def __sub__(self: NDArray[datetime64], other: _ArrayLikeTD64_co) -> NDArray[datetime64]: ...
@overload
- def __sub__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayND[timedelta64]: ...
+ def __sub__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[timedelta64]: ...
@overload
- def __sub__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __sub__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __sub__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __sub__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __sub__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64, datetime64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64, datetime64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rsub__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rsub__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rsub__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> NoReturn: ...
+ def __rsub__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
- def __rsub__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rsub__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rsub__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __rsub__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rsub__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __rsub__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __rsub__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __rsub__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __rsub__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ... # type: ignore[misc]
+ def __rsub__(self: _ArrayTD64_co, other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ... # type: ignore[misc]
@overload
- def __rsub__(self: _ArrayTD64_co, other: _ArrayLikeDT64_co) -> _ArrayND[datetime64]: ... # type: ignore[misc]
+ def __rsub__(self: _ArrayTD64_co, other: _ArrayLikeDT64_co) -> NDArray[datetime64]: ... # type: ignore[misc]
@overload
- def __rsub__(self: _ArrayND[datetime64], other: _ArrayLikeDT64_co) -> _ArrayND[timedelta64]: ...
+ def __rsub__(self: NDArray[datetime64], other: _ArrayLikeDT64_co) -> NDArray[timedelta64]: ...
@overload
- def __rsub__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rsub__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rsub__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rsub__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rsub__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64, datetime64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64, datetime64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __mul__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __mul__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __mul__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __mul__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __mul__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __mul__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __mul__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __mul__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __mul__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __mul__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __mul__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __mul__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __mul__(self: _ArrayTD64_co, other: _ArrayLikeFloat_co) -> _ArrayND[timedelta64]: ...
+ def __mul__(self: _ArrayTD64_co, other: _ArrayLikeFloat_co) -> NDArray[timedelta64]: ...
@overload
- def __mul__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ...
+ def __mul__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ...
@overload
- def __mul__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __mul__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __mul__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __mul__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __mul__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rmul__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rmul__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rmul__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __rmul__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __rmul__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rmul__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rmul__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __rmul__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rmul__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __rmul__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __rmul__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __rmul__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __rmul__(self: _ArrayTD64_co, other: _ArrayLikeFloat_co) -> _ArrayND[timedelta64]: ...
+ def __rmul__(self: _ArrayTD64_co, other: _ArrayLikeFloat_co) -> NDArray[timedelta64]: ...
@overload
- def __rmul__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ...
+ def __rmul__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ...
@overload
- def __rmul__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rmul__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rmul__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rmul__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rmul__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __floordiv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __floordiv__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __floordiv__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __floordiv__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __floordiv__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __floordiv__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __floordiv__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __floordiv__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __floordiv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __floordiv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __floordiv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __floordiv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __floordiv__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[int64]: ...
+ def __floordiv__(self: NDArray[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> NDArray[int64]: ...
@overload
- def __floordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
+ def __floordiv__(self: NDArray[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
- def __floordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeFloat_co) -> _ArrayND[timedelta64]: ...
+ def __floordiv__(self: NDArray[timedelta64], other: _ArrayLikeFloat_co) -> NDArray[timedelta64]: ...
@overload
- def __floordiv__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __floordiv__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __floordiv__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __floordiv__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __floordiv__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rfloordiv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rfloordiv__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rfloordiv__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __rfloordiv__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __rfloordiv__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rfloordiv__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rfloordiv__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __rfloordiv__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rfloordiv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __rfloordiv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __rfloordiv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __rfloordiv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __rfloordiv__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[int64]: ...
+ def __rfloordiv__(self: NDArray[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> NDArray[int64]: ...
@overload
- def __rfloordiv__(self: _ArrayND[bool_], other: _ArrayLikeTD64_co) -> NoReturn: ...
+ def __rfloordiv__(self: NDArray[bool_], other: _ArrayLikeTD64_co) -> NoReturn: ...
@overload
- def __rfloordiv__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ...
+ def __rfloordiv__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ...
@overload
- def __rfloordiv__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rfloordiv__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rfloordiv__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rfloordiv__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rfloordiv__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __pow__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __pow__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __pow__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __pow__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __pow__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __pow__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __pow__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __pow__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __pow__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __pow__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __pow__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ...
+ def __pow__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ...
@overload
- def __pow__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __pow__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __pow__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __pow__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __pow__(
- self: _ArrayND[Union[bool_, number[Any]]],
+ self: NDArray[Union[bool_, number[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rpow__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rpow__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rpow__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __rpow__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __rpow__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rpow__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rpow__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ... # type: ignore[misc]
+ def __rpow__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rpow__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __rpow__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __rpow__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ...
+ def __rpow__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ...
@overload
- def __rpow__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rpow__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rpow__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rpow__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rpow__(
- self: _ArrayND[Union[bool_, number[Any]]],
+ self: NDArray[Union[bool_, number[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __truediv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __truediv__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __truediv__(self: _ArrayInt_co, other: _ArrayInt_co) -> _ArrayND[float64]: ... # type: ignore[misc]
+ def __truediv__(self: _ArrayInt_co, other: _ArrayInt_co) -> NDArray[float64]: ... # type: ignore[misc]
@overload
- def __truediv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __truediv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __truediv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __truediv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __truediv__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[float64]: ...
+ def __truediv__(self: NDArray[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> NDArray[float64]: ...
@overload
- def __truediv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
+ def __truediv__(self: NDArray[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
- def __truediv__(self: _ArrayND[timedelta64], other: _ArrayLikeFloat_co) -> _ArrayND[timedelta64]: ...
+ def __truediv__(self: NDArray[timedelta64], other: _ArrayLikeFloat_co) -> NDArray[timedelta64]: ...
@overload
- def __truediv__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __truediv__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __truediv__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __truediv__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __truediv__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rtruediv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rtruediv__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rtruediv__(self: _ArrayInt_co, other: _ArrayInt_co) -> _ArrayND[float64]: ... # type: ignore[misc]
+ def __rtruediv__(self: _ArrayInt_co, other: _ArrayInt_co) -> NDArray[float64]: ... # type: ignore[misc]
@overload
- def __rtruediv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> _ArrayND[floating[Any]]: ... # type: ignore[misc]
+ def __rtruediv__(self: _ArrayFloat_co, other: _ArrayLikeFloat_co) -> NDArray[floating[Any]]: ... # type: ignore[misc]
@overload
- def __rtruediv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[Any, Any]]: ... # type: ignore[misc]
+ def __rtruediv__(self: _ArrayComplex_co, other: _ArrayLikeComplex_co) -> NDArray[complexfloating[Any, Any]]: ... # type: ignore[misc]
@overload
- def __rtruediv__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[float64]: ...
+ def __rtruediv__(self: NDArray[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> NDArray[float64]: ...
@overload
- def __rtruediv__(self: _ArrayND[bool_], other: _ArrayLikeTD64_co) -> NoReturn: ...
+ def __rtruediv__(self: NDArray[bool_], other: _ArrayLikeTD64_co) -> NoReturn: ...
@overload
- def __rtruediv__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ...
+ def __rtruediv__(self: _ArrayFloat_co, other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ...
@overload
- def __rtruediv__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rtruediv__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rtruediv__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rtruediv__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rtruediv__(
- self: _ArrayND[Union[bool_, number[Any], timedelta64]],
+ self: NDArray[Union[bool_, number[Any], timedelta64]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __lshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __lshift__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __lshift__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __lshift__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __lshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __lshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __lshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __lshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __lshift__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __lshift__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __lshift__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __lshift__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __lshift__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rlshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rlshift__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rlshift__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __rlshift__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __rlshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rlshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rlshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __rlshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __rlshift__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rlshift__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rlshift__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rlshift__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rlshift__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rshift__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rshift__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __rshift__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __rshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __rshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __rshift__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rshift__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rshift__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rshift__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rshift__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rrshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rrshift__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rrshift__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[int8]: ... # type: ignore[misc]
+ def __rrshift__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[int8]: ... # type: ignore[misc]
@overload
- def __rrshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rrshift__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rrshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __rrshift__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __rrshift__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rrshift__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rrshift__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rrshift__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rrshift__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __and__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __and__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __and__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __and__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __and__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __and__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __and__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __and__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __and__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __and__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __and__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __and__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __and__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rand__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rand__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rand__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __rand__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __rand__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rand__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rand__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __rand__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __rand__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rand__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rand__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rand__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rand__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __xor__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __xor__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __xor__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __xor__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __xor__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __xor__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __xor__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __xor__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __xor__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __xor__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __xor__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __xor__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __xor__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __rxor__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __rxor__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __rxor__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __rxor__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __rxor__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __rxor__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __rxor__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __rxor__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __rxor__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __rxor__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __rxor__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __rxor__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __rxor__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __or__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __or__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __or__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __or__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __or__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __or__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __or__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __or__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __or__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __or__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __or__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __or__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __or__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
@overload
- def __ror__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __ror__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __ror__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ... # type: ignore[misc]
+ def __ror__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ... # type: ignore[misc]
@overload
- def __ror__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[Any]]: ... # type: ignore[misc]
+ def __ror__(self: _ArrayUInt_co, other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[Any]]: ... # type: ignore[misc]
@overload
- def __ror__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[Any]]: ...
+ def __ror__(self: _ArrayInt_co, other: _ArrayLikeInt_co) -> NDArray[signedinteger[Any]]: ...
@overload
- def __ror__(self: _ArrayND[object_], other: Any) -> Any: ...
+ def __ror__(self: NDArray[object_], other: Any) -> Any: ...
@overload
- def __ror__(self: _ArrayND[Any], other: _ArrayLikeObject_co) -> Any: ...
+ def __ror__(self: NDArray[Any], other: _ArrayLikeObject_co) -> Any: ...
@overload
def __ror__(
- self: _ArrayND[Union[bool_, integer[Any]]],
+ self: NDArray[Union[bool_, integer[Any]]],
other: _RecursiveSequence,
) -> Any: ...
# `np.generic` does not support inplace operations
@overload # type: ignore[misc]
- def __iadd__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __iadd__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __iadd__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
+ def __iadd__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ...
@overload
- def __iadd__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __iadd__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __iadd__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __iadd__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __iadd__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
+ def __iadd__(self: NDArray[floating[_NBit1]], other: _ArrayLikeFloat_co) -> NDArray[floating[_NBit1]]: ...
@overload
- def __iadd__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
+ def __iadd__(self: NDArray[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> NDArray[complexfloating[_NBit1, _NBit1]]: ...
@overload
- def __iadd__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ...
+ def __iadd__(self: NDArray[timedelta64], other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ...
@overload
- def __iadd__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ...
+ def __iadd__(self: NDArray[datetime64], other: _ArrayLikeTD64_co) -> NDArray[datetime64]: ...
@overload
- def __iadd__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __iadd__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __iadd__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __iadd__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __isub__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __isub__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __isub__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __isub__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __isub__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __isub__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __isub__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
+ def __isub__(self: NDArray[floating[_NBit1]], other: _ArrayLikeFloat_co) -> NDArray[floating[_NBit1]]: ...
@overload
- def __isub__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
+ def __isub__(self: NDArray[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> NDArray[complexfloating[_NBit1, _NBit1]]: ...
@overload
- def __isub__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ...
+ def __isub__(self: NDArray[timedelta64], other: _ArrayLikeTD64_co) -> NDArray[timedelta64]: ...
@overload
- def __isub__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ...
+ def __isub__(self: NDArray[datetime64], other: _ArrayLikeTD64_co) -> NDArray[datetime64]: ...
@overload
- def __isub__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __isub__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __isub__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __isub__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __imul__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __imul__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __imul__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
+ def __imul__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ...
@overload
- def __imul__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __imul__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __imul__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __imul__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __imul__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
+ def __imul__(self: NDArray[floating[_NBit1]], other: _ArrayLikeFloat_co) -> NDArray[floating[_NBit1]]: ...
@overload
- def __imul__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
+ def __imul__(self: NDArray[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> NDArray[complexfloating[_NBit1, _NBit1]]: ...
@overload
- def __imul__(self: _ArrayND[timedelta64], other: _ArrayLikeFloat_co) -> _ArrayND[timedelta64]: ...
+ def __imul__(self: NDArray[timedelta64], other: _ArrayLikeFloat_co) -> NDArray[timedelta64]: ...
@overload
- def __imul__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __imul__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __imul__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __imul__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __itruediv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __itruediv__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __itruediv__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
+ def __itruediv__(self: NDArray[floating[_NBit1]], other: _ArrayLikeFloat_co) -> NDArray[floating[_NBit1]]: ...
@overload
- def __itruediv__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
+ def __itruediv__(self: NDArray[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> NDArray[complexfloating[_NBit1, _NBit1]]: ...
@overload
- def __itruediv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
+ def __itruediv__(self: NDArray[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
- def __itruediv__(self: _ArrayND[timedelta64], other: _ArrayLikeInt_co) -> _ArrayND[timedelta64]: ...
+ def __itruediv__(self: NDArray[timedelta64], other: _ArrayLikeInt_co) -> NDArray[timedelta64]: ...
@overload
- def __itruediv__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __itruediv__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __itruediv__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __itruediv__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __ifloordiv__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __ifloordiv__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __ifloordiv__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __ifloordiv__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __ifloordiv__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __ifloordiv__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __ifloordiv__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
+ def __ifloordiv__(self: NDArray[floating[_NBit1]], other: _ArrayLikeFloat_co) -> NDArray[floating[_NBit1]]: ...
@overload
- def __ifloordiv__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
+ def __ifloordiv__(self: NDArray[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> NDArray[complexfloating[_NBit1, _NBit1]]: ...
@overload
- def __ifloordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
+ def __ifloordiv__(self: NDArray[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
- def __ifloordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeInt_co) -> _ArrayND[timedelta64]: ...
+ def __ifloordiv__(self: NDArray[timedelta64], other: _ArrayLikeInt_co) -> NDArray[timedelta64]: ...
@overload
- def __ifloordiv__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __ifloordiv__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __ifloordiv__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __ifloordiv__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __ipow__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __ipow__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __ipow__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __ipow__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __ipow__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __ipow__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __ipow__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
+ def __ipow__(self: NDArray[floating[_NBit1]], other: _ArrayLikeFloat_co) -> NDArray[floating[_NBit1]]: ...
@overload
- def __ipow__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
+ def __ipow__(self: NDArray[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> NDArray[complexfloating[_NBit1, _NBit1]]: ...
@overload
- def __ipow__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __ipow__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __ipow__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __ipow__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __imod__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __imod__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __imod__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __imod__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __imod__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __imod__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __imod__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
+ def __imod__(self: NDArray[floating[_NBit1]], other: _ArrayLikeFloat_co) -> NDArray[floating[_NBit1]]: ...
@overload
- def __imod__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[timedelta64]: ...
+ def __imod__(self: NDArray[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> NDArray[timedelta64]: ...
@overload
- def __imod__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __imod__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __imod__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __imod__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __ilshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __ilshift__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __ilshift__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __ilshift__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __ilshift__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __ilshift__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __ilshift__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __ilshift__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __ilshift__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __ilshift__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __irshift__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __irshift__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __irshift__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __irshift__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __irshift__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __irshift__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __irshift__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __irshift__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __irshift__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __irshift__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __iand__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __iand__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __iand__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
+ def __iand__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ...
@overload
- def __iand__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __iand__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __iand__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __iand__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __iand__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __iand__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __iand__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __iand__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __ixor__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __ixor__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __ixor__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
+ def __ixor__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ...
@overload
- def __ixor__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __ixor__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __ixor__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __ixor__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __ixor__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __ixor__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __ixor__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __ixor__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
@overload # type: ignore[misc]
- def __ior__(self: _ArrayND[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
+ def __ior__(self: NDArray[Any], other: _NestedSequence[Union[str, bytes]]) -> NoReturn: ...
@overload
- def __ior__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
+ def __ior__(self: NDArray[bool_], other: _ArrayLikeBool_co) -> NDArray[bool_]: ...
@overload
- def __ior__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
+ def __ior__(self: NDArray[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> NDArray[unsignedinteger[_NBit1]]: ...
@overload
- def __ior__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
+ def __ior__(self: NDArray[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> NDArray[signedinteger[_NBit1]]: ...
@overload
- def __ior__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
+ def __ior__(self: NDArray[object_], other: Any) -> NDArray[object_]: ...
@overload
- def __ior__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...
+ def __ior__(self: NDArray[_ScalarType], other: _RecursiveSequence) -> NDArray[_ScalarType]: ...
# Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
@property
@@ -2827,6 +2874,25 @@ class generic(_ArrayOrScalarCommon):
axis: Optional[SupportsIndex] = ...,
) -> ndarray[Any, dtype[_ScalarType]]: ...
+ def flatten(
+ self: _ScalarType,
+ order: _OrderKACF = ...,
+ ) -> ndarray[Any, dtype[_ScalarType]]: ...
+
+ def ravel(
+ self: _ScalarType,
+ order: _OrderKACF = ...,
+ ) -> ndarray[Any, dtype[_ScalarType]]: ...
+
+ @overload
+ def reshape(
+ self: _ScalarType, __shape: _ShapeLike, *, order: _OrderACF = ...
+ ) -> ndarray[Any, dtype[_ScalarType]]: ...
+ @overload
+ def reshape(
+ self: _ScalarType, *shape: SupportsIndex, order: _OrderACF = ...
+ ) -> ndarray[Any, dtype[_ScalarType]]: ...
+
def squeeze(
self: _ScalarType, axis: Union[Literal[0], Tuple[()]] = ...
) -> _ScalarType: ...
@@ -2919,6 +2985,11 @@ class object_(generic):
def real(self: _ArraySelf) -> _ArraySelf: ...
@property
def imag(self: _ArraySelf) -> _ArraySelf: ...
+ # The 3 protocols below may or may not raise,
+ # depending on the underlying object
+ def __int__(self) -> int: ...
+ def __float__(self) -> float: ...
+ def __complex__(self) -> complex: ...
object0 = object_
@@ -3043,6 +3114,9 @@ class timedelta64(generic):
__value: Union[None, int, _CharLike_co, dt.timedelta, timedelta64] = ...,
__format: Union[_CharLike_co, Tuple[_CharLike_co, _IntLike_co]] = ...,
) -> None: ...
+
+ # NOTE: Only a limited number of units support conversion
+ # to builtin scalar types: `Y`, `M`, `ns`, `ps`, `fs`, `as`
def __int__(self) -> int: ...
def __float__(self) -> float: ...
def __complex__(self) -> complex: ...
@@ -3527,7 +3601,7 @@ class errstate(Generic[_CallType], ContextDecorator):
) -> None: ...
class ndenumerate(Generic[_ScalarType]):
- iter: flatiter[_ArrayND[_ScalarType]]
+ iter: flatiter[NDArray[_ScalarType]]
@overload
def __new__(
cls, arr: _NestedSequence[_SupportsArray[dtype[_ScalarType]]],
@@ -3553,3 +3627,45 @@ class ndindex:
def __init__(self, *shape: SupportsIndex) -> None: ...
def __iter__(self: _T) -> _T: ...
def __next__(self) -> _Shape: ...
+
+class DataSource:
+ def __init__(
+ self,
+ destpath: Union[None, str, os.PathLike[str]] = ...,
+ ) -> None: ...
+ def __del__(self) -> None: ...
+ def abspath(self, path: str) -> str: ...
+ def exists(self, path: str) -> bool: ...
+
+ # Whether the file-object is opened in string or bytes mode (by default)
+ # depends on the file-extension of `path`
+ def open(
+ self,
+ path: str,
+ mode: str = ...,
+ encoding: Optional[str] = ...,
+ newline: Optional[str] = ...,
+ ) -> IO[Any]: ...
+
+# TODO: The type of each `__next__` and `iters` return-type depends
+# on the length and dtype of `args`; we can't describe this behavior yet
+# as we lack variadics (PEP 646).
+class broadcast:
+ def __new__(cls, *args: ArrayLike) -> broadcast: ...
+ @property
+ def index(self) -> int: ...
+ @property
+ def iters(self) -> Tuple[flatiter[Any], ...]: ...
+ @property
+ def nd(self) -> int: ...
+ @property
+ def ndim(self) -> int: ...
+ @property
+ def numiter(self) -> int: ...
+ @property
+ def shape(self) -> _Shape: ...
+ @property
+ def size(self) -> int: ...
+ def __next__(self) -> Tuple[Any, ...]: ...
+ def __iter__(self: _T) -> _T: ...
+ def reset(self) -> None: ...
diff --git a/numpy/core/_add_newdocs.py b/numpy/core/_add_newdocs.py
index f870dc8ad..538123149 100644
--- a/numpy/core/_add_newdocs.py
+++ b/numpy/core/_add_newdocs.py
@@ -2176,6 +2176,8 @@ add_newdoc('numpy.core.multiarray', 'ndarray',
empty : Create an array, but leave its allocated memory unchanged (i.e.,
it contains "garbage").
dtype : Create a data-type.
+ numpy.typing.NDArray : A :term:`generic <generic type>` version
+ of ndarray.
Notes
-----
@@ -5814,7 +5816,7 @@ add_newdoc('numpy.core.multiarray', 'dtype', ('metadata',
>>> (arr + arr).dtype.metadata
mappingproxy({'key': 'value'})
- But if the arrays have different dtype metadata, the metadata may be
+ But if the arrays have different dtype metadata, the metadata may be
dropped:
>>> dt2 = np.dtype(float, metadata={"key2": "value2"})
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py
index 5c7b3372b..65a42eb1e 100644
--- a/numpy/core/fromnumeric.py
+++ b/numpy/core/fromnumeric.py
@@ -2498,6 +2498,10 @@ def cumsum(a, axis=None, dtype=None, out=None):
Arithmetic is modular when using integer types, and no error is
raised on overflow.
+ ``cumsum(a)[-1]`` may not be equal to ``sum(a)`` for floating-point
+ values since ``sum`` may use a pairwise summation routine, reducing
+ the roundoff-error. See `sum` for more information.
+
Examples
--------
>>> a = np.array([[1,2,3], [4,5,6]])
@@ -2516,6 +2520,14 @@ def cumsum(a, axis=None, dtype=None, out=None):
array([[ 1, 3, 6],
[ 4, 9, 15]])
+ ``cumsum(b)[-1]`` may not be equal to ``sum(b)``
+
+ >>> b = np.array([1, 2e-9, 3e-9] * 1000000)
+ >>> b.cumsum()[-1]
+ 1000000.0050045159
+ >>> b.sum()
+ 1000000.0050000029
+
"""
return _wrapfunc(a, 'cumsum', axis=axis, dtype=dtype, out=out)
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index 0f24d814f..dacb72022 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -1225,8 +1225,6 @@ struct PyArrayIterObject_tag {
_PyAIT(it)->dataptr = PyArray_BYTES(_PyAIT(it)->ao); \
for (__npy_i = 0; __npy_i<=_PyAIT(it)->nd_m1; \
__npy_i++) { \
- _PyAIT(it)->coordinates[__npy_i] = \
- (__npy_ind / _PyAIT(it)->factors[__npy_i]); \
_PyAIT(it)->dataptr += \
(__npy_ind / _PyAIT(it)->factors[__npy_i]) \
* _PyAIT(it)->strides[__npy_i]; \
diff --git a/numpy/core/src/common/simd/avx2/math.h b/numpy/core/src/common/simd/avx2/math.h
index 22659e21b..9460183df 100644
--- a/numpy/core/src/common/simd/avx2/math.h
+++ b/numpy/core/src/common/simd/avx2/math.h
@@ -105,4 +105,4 @@ NPY_FINLINE npyv_s64 npyv_min_s64(npyv_s64 a, npyv_s64 b)
return _mm256_blendv_epi8(a, b, _mm256_cmpgt_epi64(a, b));
}
-#endif
+#endif // _NPY_SIMD_AVX2_MATH_H
diff --git a/numpy/core/src/common/simd/avx512/math.h b/numpy/core/src/common/simd/avx512/math.h
index b75651962..0141396d0 100644
--- a/numpy/core/src/common/simd/avx512/math.h
+++ b/numpy/core/src/common/simd/avx512/math.h
@@ -112,4 +112,4 @@ NPY_FINLINE npyv_f64 npyv_minp_f64(npyv_f64 a, npyv_f64 b)
#define npyv_min_u64 _mm512_min_epu64
#define npyv_min_s64 _mm512_min_epi64
-#endif
+#endif // _NPY_SIMD_AVX512_MATH_H
diff --git a/numpy/core/src/common/simd/neon/math.h b/numpy/core/src/common/simd/neon/math.h
index a5508c96b..ced82d1de 100644
--- a/numpy/core/src/common/simd/neon/math.h
+++ b/numpy/core/src/common/simd/neon/math.h
@@ -153,4 +153,4 @@ NPY_FINLINE npyv_s64 npyv_min_s64(npyv_s64 a, npyv_s64 b)
return vbslq_s64(npyv_cmplt_s64(a, b), a, b);
}
-#endif // _NPY_SIMD_SSE_MATH_H
+#endif // _NPY_SIMD_NEON_MATH_H
diff --git a/numpy/core/src/common/simd/sse/math.h b/numpy/core/src/common/simd/sse/math.h
index 1f82b546f..97d35afc5 100644
--- a/numpy/core/src/common/simd/sse/math.h
+++ b/numpy/core/src/common/simd/sse/math.h
@@ -143,4 +143,4 @@ NPY_FINLINE npyv_s64 npyv_min_s64(npyv_s64 a, npyv_s64 b)
return npyv_select_s64(npyv_cmplt_s64(a, b), a, b);
}
-#endif
+#endif // _NPY_SIMD_SSE_MATH_H
diff --git a/numpy/core/src/multiarray/_multiarray_tests.c.src b/numpy/core/src/multiarray/_multiarray_tests.c.src
index b2c6d1461..ba10573d9 100644
--- a/numpy/core/src/multiarray/_multiarray_tests.c.src
+++ b/numpy/core/src/multiarray/_multiarray_tests.c.src
@@ -87,7 +87,7 @@ static int copy_@name@(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *ni
* For each point in itx, copy the current neighborhood into an array which
* is appended at the output list
*/
- for (i = itx->index; i < itx->size; ++i) {
+ for (i = 0; i < itx->size; ++i) {
PyArrayNeighborhoodIter_Reset(niterx);
for (j = 0; j < PyArray_NDIM(itx->ao); ++j) {
@@ -130,7 +130,7 @@ static int copy_object(PyArrayIterObject *itx, PyArrayNeighborhoodIterObject *ni
* For each point in itx, copy the current neighborhood into an array which
* is appended at the output list
*/
- for (i = itx->index; i < itx->size; ++i) {
+ for (i = 0; i < itx->size; ++i) {
PyArrayNeighborhoodIter_Reset(niterx);
for (j = 0; j < PyArray_NDIM(itx->ao); ++j) {
@@ -161,11 +161,10 @@ test_neighborhood_iterator(PyObject* NPY_UNUSED(self), PyObject* args)
PyArrayObject *ax, *afill;
PyArrayIterObject *itx;
int i, typenum, mode, st;
- Py_ssize_t idxstart = 0;
npy_intp bounds[NPY_MAXDIMS*2];
PyArrayNeighborhoodIterObject *niterx;
- if (!PyArg_ParseTuple(args, "OOOi|n", &x, &b, &fill, &mode, &idxstart)) {
+ if (!PyArg_ParseTuple(args, "OOOi", &x, &b, &fill, &mode)) {
return NULL;
}
@@ -225,14 +224,6 @@ test_neighborhood_iterator(PyObject* NPY_UNUSED(self), PyObject* args)
}
}
- if (idxstart >= itx->size || idxstart < 0) {
- PyErr_SetString(PyExc_ValueError,
- "start index not compatible with x input");
- goto clean_itx;
- }
-
- PyArray_ITER_GOTO1D((PyArrayIterObject*)itx, idxstart);
-
niterx = (PyArrayNeighborhoodIterObject*)PyArray_NeighborhoodIterNew(
(PyArrayIterObject*)itx, bounds, mode, afill);
if (niterx == NULL) {
@@ -416,7 +407,7 @@ test_neighborhood_iterator_oob(PyObject* NPY_UNUSED(self), PyObject* args)
niterx2 = (PyArrayNeighborhoodIterObject*)PyArray_NeighborhoodIterNew(
(PyArrayIterObject*)niterx1, bounds,
mode2, NULL);
- if (niterx1 == NULL) {
+ if (niterx2 == NULL) {
goto clean_niterx1;
}
diff --git a/numpy/core/src/multiarray/array_coercion.c b/numpy/core/src/multiarray/array_coercion.c
index ef99ae479..6b7c3888d 100644
--- a/numpy/core/src/multiarray/array_coercion.c
+++ b/numpy/core/src/multiarray/array_coercion.c
@@ -622,8 +622,12 @@ handle_promotion(PyArray_Descr **out_descr, PyArray_Descr *descr,
}
PyArray_Descr *new_descr = PyArray_PromoteTypes(descr, *out_descr);
if (NPY_UNLIKELY(new_descr == NULL)) {
- if (fixed_DType != NULL) {
- /* If a DType is fixed, promotion must not fail. */
+ if (fixed_DType != NULL || PyErr_ExceptionMatches(PyExc_FutureWarning)) {
+ /*
+ * If a DType is fixed, promotion must not fail. Do not catch
+ * FutureWarning (raised for string+numeric promotions). We could
+ * only catch TypeError here or even always raise the error.
+ */
return -1;
}
PyErr_Clear();
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c
index 7907fb930..671ce49e4 100644
--- a/numpy/core/src/multiarray/ctors.c
+++ b/numpy/core/src/multiarray/ctors.c
@@ -665,13 +665,11 @@ PyArray_NewFromDescr_int(
int allow_emptystring)
{
PyArrayObject_fields *fa;
- int i;
npy_intp nbytes;
- if ((unsigned int)nd > (unsigned int)NPY_MAXDIMS) {
+ if (nd > NPY_MAXDIMS || nd < 0) {
PyErr_Format(PyExc_ValueError,
- "number of dimensions must be within [0, %d]",
- NPY_MAXDIMS);
+ "number of dimensions must be within [0, %d]", NPY_MAXDIMS);
Py_DECREF(descr);
return NULL;
}
@@ -718,39 +716,6 @@ PyArray_NewFromDescr_int(
}
}
- /* Check dimensions and multiply them to nbytes */
- for (i = 0; i < nd; i++) {
- npy_intp dim = dims[i];
-
- if (dim == 0) {
- /*
- * Compare to PyArray_OverflowMultiplyList that
- * returns 0 in this case.
- */
- continue;
- }
-
- if (dim < 0) {
- PyErr_SetString(PyExc_ValueError,
- "negative dimensions are not allowed");
- Py_DECREF(descr);
- return NULL;
- }
-
- /*
- * Care needs to be taken to avoid integer overflow when
- * multiplying the dimensions together to get the total size of the
- * array.
- */
- if (npy_mul_with_overflow_intp(&nbytes, nbytes, dim)) {
- PyErr_SetString(PyExc_ValueError,
- "array is too big; `arr.size * arr.dtype.itemsize` "
- "is larger than the maximum possible size.");
- Py_DECREF(descr);
- return NULL;
- }
- }
-
fa = (PyArrayObject_fields *) subtype->tp_alloc(subtype, 0);
if (fa == NULL) {
Py_DECREF(descr);
@@ -786,26 +751,57 @@ PyArray_NewFromDescr_int(
goto fail;
}
fa->strides = fa->dimensions + nd;
- if (nd) {
- memcpy(fa->dimensions, dims, sizeof(npy_intp)*nd);
+
+ /* Copy dimensions, check them, and find total array size `nbytes` */
+ for (int i = 0; i < nd; i++) {
+ fa->dimensions[i] = dims[i];
+
+ if (fa->dimensions[i] == 0) {
+ /*
+ * Compare to PyArray_OverflowMultiplyList that
+ * returns 0 in this case.
+ */
+ continue;
+ }
+
+ if (fa->dimensions[i] < 0) {
+ PyErr_SetString(PyExc_ValueError,
+ "negative dimensions are not allowed");
+ goto fail;
+ }
+
+ /*
+ * Care needs to be taken to avoid integer overflow when multiplying
+ * the dimensions together to get the total size of the array.
+ */
+ if (npy_mul_with_overflow_intp(&nbytes, nbytes, fa->dimensions[i])) {
+ PyErr_SetString(PyExc_ValueError,
+ "array is too big; `arr.size * arr.dtype.itemsize` "
+ "is larger than the maximum possible size.");
+ goto fail;
+ }
}
- if (strides == NULL) { /* fill it in */
+
+ /* Fill the strides (or copy them if they were passed in) */
+ if (strides == NULL) {
+ /* fill the strides and set the contiguity flags */
_array_fill_strides(fa->strides, dims, nd, descr->elsize,
flags, &(fa->flags));
}
else {
- /*
- * we allow strides even when we create
- * the memory, but be careful with this...
- */
- if (nd) {
- memcpy(fa->strides, strides, sizeof(npy_intp)*nd);
+ /* User to provided strides (user is responsible for correctness) */
+ for (int i = 0; i < nd; i++) {
+ fa->strides[i] = strides[i];
}
+ /* Since the strides were passed in must update contiguity */
+ PyArray_UpdateFlags((PyArrayObject *)fa,
+ NPY_ARRAY_C_CONTIGUOUS|NPY_ARRAY_F_CONTIGUOUS);
}
}
else {
- fa->dimensions = fa->strides = NULL;
- fa->flags |= NPY_ARRAY_F_CONTIGUOUS;
+ fa->dimensions = NULL;
+ fa->strides = NULL;
+ fa->flags |= NPY_ARRAY_C_CONTIGUOUS|NPY_ARRAY_F_CONTIGUOUS;
}
if (data == NULL) {
@@ -844,12 +840,11 @@ PyArray_NewFromDescr_int(
fa->data = data;
/*
- * always update the flags to get the right CONTIGUOUS, ALIGN properties
- * not owned data and input strides may not be aligned and on some
- * platforms (debian sparc) malloc does not provide enough alignment for
- * long double types
+ * Always update the aligned flag. Not owned data or input strides may
+ * not be aligned. Also on some platforms (debian sparc) malloc does not
+ * provide enough alignment for long double types.
*/
- PyArray_UpdateFlags((PyArrayObject *)fa, NPY_ARRAY_UPDATE_ALL);
+ PyArray_UpdateFlags((PyArrayObject *)fa, NPY_ARRAY_ALIGNED);
/* Set the base object. It's important to do it here so that
* __array_finalize__ below receives it
@@ -862,15 +857,20 @@ PyArray_NewFromDescr_int(
}
/*
- * call the __array_finalize__
- * method if a subtype.
- * If obj is NULL, then call method with Py_None
+ * call the __array_finalize__ method if a subtype was requested.
+ * If obj is NULL use Py_None for the Python callback.
*/
- if ((subtype != &PyArray_Type)) {
- PyObject *res, *func, *args;
+ if (subtype != &PyArray_Type) {
+ PyObject *res, *func;
func = PyObject_GetAttr((PyObject *)fa, npy_ma_str_array_finalize);
- if (func && func != Py_None) {
+ if (func == NULL) {
+ goto fail;
+ }
+ else if (func == Py_None) {
+ Py_DECREF(func);
+ }
+ else {
if (PyCapsule_CheckExact(func)) {
/* A C-function is stored here */
PyArray_FinalizeFunc *cfunc;
@@ -884,14 +884,10 @@ PyArray_NewFromDescr_int(
}
}
else {
- args = PyTuple_New(1);
if (obj == NULL) {
- obj=Py_None;
+ obj = Py_None;
}
- Py_INCREF(obj);
- PyTuple_SET_ITEM(args, 0, obj);
- res = PyObject_Call(func, args, NULL);
- Py_DECREF(args);
+ res = PyObject_CallFunctionObjArgs(func, obj, NULL);
Py_DECREF(func);
if (res == NULL) {
goto fail;
@@ -901,7 +897,6 @@ PyArray_NewFromDescr_int(
}
}
}
- else Py_XDECREF(func);
}
return (PyObject *)fa;
diff --git a/numpy/core/src/multiarray/iterators.c b/numpy/core/src/multiarray/iterators.c
index 4a42d742e..3ebd4c858 100644
--- a/numpy/core/src/multiarray/iterators.c
+++ b/numpy/core/src/multiarray/iterators.c
@@ -1772,9 +1772,6 @@ PyArray_NeighborhoodIterNew(PyArrayIterObject *x, const npy_intp *bounds,
*/
x->contiguous = 0;
- /* update the coordinates if x was contiguous before */
- PyArray_ITER_GOTO1D(x, x->index);
-
PyArrayNeighborhoodIter_Reset(ret);
return (PyObject*)ret;
diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c
index 2197fe798..a0154e474 100644
--- a/numpy/core/src/multiarray/nditer_constr.c
+++ b/numpy/core/src/multiarray/nditer_constr.c
@@ -594,8 +594,10 @@ NpyIter_Copy(NpyIter *iter)
if (buffers[iop] == NULL) {
out_of_memory = 1;
}
- if (PyDataType_FLAGCHK(dtypes[iop], NPY_NEEDS_INIT)) {
- memset(buffers[iop], '\0', itemsize*buffersize);
+ else {
+ if (PyDataType_FLAGCHK(dtypes[iop], NPY_NEEDS_INIT)) {
+ memset(buffers[iop], '\0', itemsize*buffersize);
+ }
}
}
}
diff --git a/numpy/core/src/umath/_umath_tests.c.src b/numpy/core/src/umath/_umath_tests.c.src
index 7cc74a4f3..2e79d377e 100644
--- a/numpy/core/src/umath/_umath_tests.c.src
+++ b/numpy/core/src/umath/_umath_tests.c.src
@@ -532,7 +532,7 @@ UMath_Tests_test_signature(PyObject *NPY_UNUSED(dummy), PyObject *args)
}
if (f->core_dim_ixs != NULL) {
core_dim_ixs = PyTuple_New(core_num_ixs);
- if (core_num_dims == NULL) {
+ if (core_dim_ixs == NULL) {
goto fail;
}
for (i = 0; i < core_num_ixs; i++) {
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c
index 7dffb482f..0644a28c0 100644
--- a/numpy/core/src/umath/ufunc_object.c
+++ b/numpy/core/src/umath/ufunc_object.c
@@ -4542,10 +4542,15 @@ _get_normalized_typetup(PyUFuncObject *ufunc,
"Cannot provide `dtype` when a ufunc has no outputs");
return -1;
}
- signature[nin] = _get_dtype(dtype_obj);
- if (signature[nin] == NULL) {
+ PyArray_DTypeMeta *dtype = _get_dtype(dtype_obj);
+ if (dtype == NULL) {
return -1;
}
+ for (int i = nin; i < nop; i++) {
+ Py_INCREF(dtype);
+ signature[i] = dtype;
+ }
+ Py_DECREF(dtype);
res = _make_new_typetup(nop, signature, out_typetup);
goto finish;
}
diff --git a/numpy/core/src/umath/ufunc_type_resolution.c b/numpy/core/src/umath/ufunc_type_resolution.c
index a3f97a8f3..2834235e4 100644
--- a/numpy/core/src/umath/ufunc_type_resolution.c
+++ b/numpy/core/src/umath/ufunc_type_resolution.c
@@ -288,7 +288,7 @@ PyUFunc_DefaultTypeResolver(PyUFuncObject *ufunc,
} else {
/* Find the specified ufunc inner loop, and fill in the dtypes */
retval = type_tuple_type_resolver(ufunc, type_tup,
- operands, casting, any_object, out_dtypes);
+ operands, input_casting, casting, any_object, out_dtypes);
}
return retval;
@@ -558,6 +558,11 @@ PyUFunc_SimpleUniformOperationTypeResolver(
* This is a fast-path, since all descriptors will be identical, mainly
* when only a single descriptor was passed (which would set the out
* one in the tuple), there is no need to check all loops.
+ * Note that this also allows (None, None, float64) to resolve to
+ * (float64, float64, float64), even when the inputs do not match,
+ * i.e. fixing the output part of the signature can fix all of them.
+ * This is necessary to support `nextafter(1., inf, dtype=float32)`,
+ * where it is "clear" we want to cast 1. and inf to float32.
*/
PyArray_Descr *descr = NULL;
if (PyTuple_CheckExact(type_tup) &&
@@ -565,7 +570,12 @@ PyUFunc_SimpleUniformOperationTypeResolver(
for (int i = 0; i < nop; i++) {
PyObject *item = PyTuple_GET_ITEM(type_tup, i);
if (item == Py_None) {
- continue;
+ if (i < ufunc->nin) {
+ continue;
+ }
+ /* All outputs must be set (this could be relaxed) */
+ descr = NULL;
+ break;
}
if (!PyArray_DescrCheck(item)) {
/* Defer to default resolver (will raise an error there) */
@@ -1661,6 +1671,9 @@ ufunc_loop_matches(PyUFuncObject *self,
if (types[i] == NPY_OBJECT && !any_object && self->ntypes > 1) {
return 0;
}
+ if (types[i] == NPY_NOTYPE) {
+ continue; /* Matched by being explicitly specified. */
+ }
/*
* If type num is NPY_VOID and struct dtypes have been passed in,
@@ -1710,6 +1723,9 @@ ufunc_loop_matches(PyUFuncObject *self,
* outputs.
*/
for (i = nin; i < nop; ++i) {
+ if (types[i] == NPY_NOTYPE) {
+ continue; /* Matched by being explicitly specified. */
+ }
if (op[i] != NULL) {
PyArray_Descr *tmp = PyArray_DescrFromType(types[i]);
if (tmp == NULL) {
@@ -1728,7 +1744,6 @@ ufunc_loop_matches(PyUFuncObject *self,
Py_DECREF(tmp);
}
}
-
return 1;
}
@@ -1869,12 +1884,15 @@ type_tuple_userloop_type_resolver(PyUFuncObject *self,
int n_specified,
int *specified_types,
PyArrayObject **op,
+ NPY_CASTING input_casting,
NPY_CASTING casting,
int any_object,
int use_min_scalar,
PyArray_Descr **out_dtype)
{
int i, j, nin = self->nin, nop = nin + self->nout;
+ assert(n_specified == nop);
+ int types[NPY_MAXARGS];
/* Use this to try to avoid repeating the same userdef loop search */
int last_userdef = -1;
@@ -1907,28 +1925,31 @@ type_tuple_userloop_type_resolver(PyUFuncObject *self,
return -1;
}
for (; funcdata != NULL; funcdata = funcdata->next) {
- int *types = funcdata->arg_types;
- int matched = 1;
-
- if (n_specified == nop) {
- for (j = 0; j < nop; ++j) {
- if (types[j] != specified_types[j] &&
- specified_types[j] != NPY_NOTYPE) {
- matched = 0;
- break;
- }
+ int *orig_types = funcdata->arg_types;
+
+ /*
+ * Copy the types into an int array for matching
+ * (Mostly duplicated in `type_tuple_type_resolver`)
+ */
+ for (j = 0; j < nop; ++j) {
+ if (specified_types[j] == NPY_NOTYPE) {
+ types[j] = orig_types[j];
+ continue;
}
- } else {
- if (types[nin] != specified_types[0]) {
- matched = 0;
+ if (orig_types[j] != specified_types[j]) {
+ break;
}
+ /* indicate that we do not have to check this type anymore. */
+ types[j] = NPY_NOTYPE;
}
- if (!matched) {
+
+ if (j != nop) {
+ /* no match */
continue;
}
switch (ufunc_loop_matches(self, op,
- casting, casting,
+ input_casting, casting,
any_object, use_min_scalar,
types, NULL,
&no_castable_output, &err_src_typecode,
@@ -1936,7 +1957,19 @@ type_tuple_userloop_type_resolver(PyUFuncObject *self,
/* It works */
case 1:
set_ufunc_loop_data_types(self, op,
- out_dtype, types, NULL);
+ out_dtype, orig_types, NULL);
+ /*
+ * In principle, we only need to validate the
+ * NPY_NOTYPE ones
+ */
+ if (PyUFunc_ValidateCasting(self,
+ casting, op, out_dtype) < 0) {
+ for (j = 0; j < self->nargs; j++) {
+ Py_DECREF(out_dtype[j]);
+ out_dtype[j] = NULL;
+ }
+ return -1;
+ }
return 1;
/* Didn't match */
case 0:
@@ -2069,6 +2102,94 @@ linear_search_type_resolver(PyUFuncObject *self,
return -1;
}
+
+static int
+type_tuple_type_resolver_core(PyUFuncObject *self,
+ PyArrayObject **op,
+ NPY_CASTING input_casting, NPY_CASTING casting,
+ int specified_types[],
+ int any_object,
+ int no_castable_output, int use_min_scalar,
+ PyArray_Descr **out_dtype)
+{
+ int i, j;
+ int nop = self->nargs;
+ int types[NPY_MAXARGS];
+
+ /* For making a better error message on coercion error */
+ char err_dst_typecode = '-', err_src_typecode = '-';
+
+ /* If the ufunc has userloops, search for them. */
+ if (self->userloops) {
+ switch (type_tuple_userloop_type_resolver(self,
+ nop, specified_types,
+ op, input_casting, casting,
+ any_object, use_min_scalar,
+ out_dtype)) {
+ /* Error */
+ case -1:
+ return -1;
+ /* Found matching loop */
+ case 1:
+ return 0;
+ }
+ }
+
+ for (i = 0; i < self->ntypes; ++i) {
+ char *orig_types = self->types + i*self->nargs;
+
+ /*
+ * Check specified types and copy into an int array for matching
+ * (Mostly duplicated in `type_tuple_userloop_type_resolver`)
+ */
+ for (j = 0; j < nop; ++j) {
+ if (specified_types[j] == NPY_NOTYPE) {
+ types[j] = orig_types[j];
+ continue;
+ }
+ if (orig_types[j] != specified_types[j]) {
+ break;
+ }
+ /* indicate that we do not have to check this type anymore. */
+ types[j] = NPY_NOTYPE;
+ }
+ if (j < nop) {
+ /* no match */
+ continue;
+ }
+
+ switch (ufunc_loop_matches(self, op,
+ input_casting, casting,
+ any_object, use_min_scalar,
+ types, NULL,
+ &no_castable_output, &err_src_typecode,
+ &err_dst_typecode)) {
+ case -1:
+ /* Error */
+ return -1;
+ case 0:
+ /* Cannot cast inputs */
+ continue;
+ case 1:
+ /* Success, fill also the NPY_NOTYPE (cast from char to int) */
+ for (j = 0; j < nop; j++) {
+ types[j] = orig_types[j];
+ }
+ set_ufunc_loop_data_types(self, op, out_dtype, types, NULL);
+ /* In principle, we only need to validate the NPY_NOTYPE ones */
+ if (PyUFunc_ValidateCasting(self, casting, op, out_dtype) < 0) {
+ for (j = 0; j < self->nargs; j++) {
+ Py_DECREF(out_dtype[j]);
+ out_dtype[j] = NULL;
+ }
+ return -1;
+ }
+ return 0;
+ }
+ }
+ return -2;
+}
+
/*
* Does a linear search for the inner loop of the ufunc specified by type_tup.
*
@@ -2079,18 +2200,16 @@ NPY_NO_EXPORT int
type_tuple_type_resolver(PyUFuncObject *self,
PyObject *type_tup,
PyArrayObject **op,
+ NPY_CASTING input_casting,
NPY_CASTING casting,
int any_object,
PyArray_Descr **out_dtype)
{
- int i, j, nin = self->nin, nop = nin + self->nout;
- int specified_types[NPY_MAXARGS], types[NPY_MAXARGS];
+ int nin = self->nin, nop = nin + self->nout;
+ int specified_types[NPY_MAXARGS];
const char *ufunc_name;
int no_castable_output = 0, use_min_scalar;
- /* For making a better error message on coercion error */
- char err_dst_typecode = '-', err_src_typecode = '-';
-
ufunc_name = ufunc_get_name_cstr(self);
use_min_scalar = should_use_min_scalar(nin, op, 0, NULL);
@@ -2112,7 +2231,7 @@ type_tuple_type_resolver(PyUFuncObject *self,
PyErr_SetString(PyExc_RuntimeError, bad_type_tup_msg);
return -1;
}
- for (i = 0; i < nop; ++i) {
+ for (int i = 0; i < nop; ++i) {
PyObject *item = PyTuple_GET_ITEM(type_tup, i);
if (item == Py_None) {
specified_types[i] = NPY_NOTYPE;
@@ -2131,57 +2250,51 @@ type_tuple_type_resolver(PyUFuncObject *self,
return -1;
}
- /* If the ufunc has userloops, search for them. */
- if (self->userloops) {
- switch (type_tuple_userloop_type_resolver(self,
- nop, specified_types,
- op, casting,
- any_object, use_min_scalar,
- out_dtype)) {
- /* Error */
- case -1:
- return -1;
- /* Found matching loop */
- case 1:
- return 0;
- }
- }
-
- for (i = 0; i < self->ntypes; ++i) {
- char *orig_types = self->types + i*self->nargs;
+ int res = type_tuple_type_resolver_core(self,
+ op, input_casting, casting, specified_types, any_object,
+ no_castable_output, use_min_scalar, out_dtype);
- /* Copy the types into an int array for matching */
- for (j = 0; j < nop; ++j) {
- types[j] = orig_types[j];
- }
+ if (res != -2) {
+ return res;
+ }
- for (j = 0; j < nop; ++j) {
- if (types[j] != specified_types[j] &&
- specified_types[j] != NPY_NOTYPE) {
+ /*
+ * When the user passes `dtype=dtype`, it gets translated to
+ * `signature=(None,)*nin + (dtype,)*nout`. If the signature matches that
+ * exactly (could be relaxed but that is not necessary for backcompat),
+ * we also try `signature=(dtype,)*(nin+nout)`.
+ * This used to be the main meaning for `dtype=dtype`, but some calls broke
+ * the expectation, and changing it allows for `dtype=dtype` to be useful
+ * for ufuncs like `np.ldexp` in the future while also normalizing it to
+ * a `signature` early on.
+ */
+ int homogeneous_type = NPY_NOTYPE;
+ if (self->nout > 0) {
+ homogeneous_type = specified_types[nin];
+ for (int i = nin+1; i < nop; i++) {
+ if (specified_types[i] != homogeneous_type) {
+ homogeneous_type = NPY_NOTYPE;
break;
}
}
- if (j < nop) {
- /* no match */
- continue;
+ }
+ if (homogeneous_type != NPY_NOTYPE) {
+ for (int i = 0; i < nin; i++) {
+ if (specified_types[i] != NPY_NOTYPE) {
+ homogeneous_type = NPY_NOTYPE;
+ break;
+ }
+ specified_types[i] = homogeneous_type;
}
+ }
+ if (homogeneous_type != NPY_NOTYPE) {
+ /* Try again with the homogeneous specified types. */
+ res = type_tuple_type_resolver_core(self,
+ op, input_casting, casting, specified_types, any_object,
+ no_castable_output, use_min_scalar, out_dtype);
- switch (ufunc_loop_matches(self, op,
- casting, casting,
- any_object, use_min_scalar,
- types, NULL,
- &no_castable_output, &err_src_typecode,
- &err_dst_typecode)) {
- case -1:
- /* Error */
- return -1;
- case 0:
- /* Cannot cast inputs */
- continue;
- case 1:
- /* Success */
- set_ufunc_loop_data_types(self, op, out_dtype, types, NULL);
- return 0;
+ if (res != -2) {
+ return res;
}
}
diff --git a/numpy/core/src/umath/ufunc_type_resolution.h b/numpy/core/src/umath/ufunc_type_resolution.h
index 1d6ad3358..b11c69852 100644
--- a/numpy/core/src/umath/ufunc_type_resolution.h
+++ b/numpy/core/src/umath/ufunc_type_resolution.h
@@ -123,6 +123,7 @@ NPY_NO_EXPORT int
type_tuple_type_resolver(PyUFuncObject *self,
PyObject *type_tup,
PyArrayObject **op,
+ NPY_CASTING input_casting,
NPY_CASTING casting,
int any_object,
PyArray_Descr **out_dtype);
diff --git a/numpy/core/tests/test_deprecations.py b/numpy/core/tests/test_deprecations.py
index ec4112e69..ed1688374 100644
--- a/numpy/core/tests/test_deprecations.py
+++ b/numpy/core/tests/test_deprecations.py
@@ -1121,10 +1121,7 @@ class TestStringPromotion(_DeprecationTestCase):
self.assert_deprecated(lambda: np.concatenate((arr1, arr2), axis=0))
self.assert_deprecated(lambda: np.concatenate((arr1, arr2), axis=None))
- # coercing to an array is similar, but will fall-back to `object`
- # (when raising the FutureWarning, this already happens)
- self.assert_deprecated(lambda: np.array([arr1[0], arr2[0]]),
- exceptions=())
+ self.assert_deprecated(lambda: np.array([arr1[0], arr2[0]]))
@pytest.mark.parametrize("dtype", "?bhilqpBHILQPefdgFDG")
@pytest.mark.parametrize("string_dt", ["S", "U"])
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index 6df5e8467..d567653f5 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -5982,6 +5982,7 @@ class TestStats:
res = dat.var(1)
assert_(res.info == dat.info)
+
class TestVdot:
def test_basic(self):
dt_numeric = np.typecodes['AllFloat'] + np.typecodes['AllInteger']
@@ -6946,13 +6947,6 @@ class TestNeighborhoodIter:
x, [-1, 0, -1, 1], 4, NEIGH_MODE['constant'])
assert_array_equal(l, r)
- # Test with start in the middle
- r = [np.array([[4, 0, 1], [4, 2, 3]], dtype=dt),
- np.array([[0, 1, 4], [2, 3, 4]], dtype=dt)]
- l = _multiarray_tests.test_neighborhood_iterator(
- x, [-1, 0, -1, 1], 4, NEIGH_MODE['constant'], 2)
- assert_array_equal(l, r)
-
def test_mirror2d(self, dt):
x = np.array([[0, 1], [2, 3]], dtype=dt)
r = [np.array([[0, 0, 1], [0, 0, 1]], dtype=dt),
@@ -8707,6 +8701,15 @@ class TestArrayFinalize:
a = np.array(1).view(SavesBase)
assert_(a.saved_base is a.base)
+ def test_bad_finalize(self):
+ class BadAttributeArray(np.ndarray):
+ @property
+ def __array_finalize__(self):
+ raise RuntimeError("boohoo!")
+
+ with pytest.raises(RuntimeError, match="boohoo!"):
+ np.arange(10).view(BadAttributeArray)
+
def test_lifetime_on_error(self):
# gh-11237
class RaisesInFinalize(np.ndarray):
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index d1af7f1d8..25198bba9 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -503,8 +503,8 @@ class TestRegression:
assert_equal(np.arange(4, dtype='<c8').real.max(), 3.0)
def test_object_array_from_list(self):
- # Ticket #270
- assert_(np.array([1, 'A', None]).shape == (3,))
+ # Ticket #270 (gh-868)
+ assert_(np.array([1, None, 'A']).shape == (3,))
def test_multiple_assign(self):
# Ticket #273
@@ -2052,18 +2052,18 @@ class TestRegression:
def test_string_truncation(self):
# Ticket #1990 - Data can be truncated in creation of an array from a
- # mixed sequence of numeric values and strings
+ # mixed sequence of numeric values and strings (gh-2583)
for val in [True, 1234, 123.4, complex(1, 234)]:
- for tostr in [asunicode, asbytes]:
- b = np.array([val, tostr('xx')])
+ for tostr, dtype in [(asunicode, "U"), (asbytes, "S")]:
+ b = np.array([val, tostr('xx')], dtype=dtype)
assert_equal(tostr(b[0]), tostr(val))
- b = np.array([tostr('xx'), val])
+ b = np.array([tostr('xx'), val], dtype=dtype)
assert_equal(tostr(b[1]), tostr(val))
# test also with longer strings
- b = np.array([val, tostr('xxxxxxxxxx')])
+ b = np.array([val, tostr('xxxxxxxxxx')], dtype=dtype)
assert_equal(tostr(b[0]), tostr(val))
- b = np.array([tostr('xxxxxxxxxx'), val])
+ b = np.array([tostr('xxxxxxxxxx'), val], dtype=dtype)
assert_equal(tostr(b[1]), tostr(val))
def test_string_truncation_ucs2(self):
diff --git a/numpy/core/tests/test_scalar_methods.py b/numpy/core/tests/test_scalar_methods.py
index 4f5fd2988..3693bba59 100644
--- a/numpy/core/tests/test_scalar_methods.py
+++ b/numpy/core/tests/test_scalar_methods.py
@@ -89,7 +89,8 @@ class TestAsIntegerRatio:
])
def test_roundtrip(self, ftype, frac_vals, exp_vals):
for frac, exp in zip(frac_vals, exp_vals):
- f = np.ldexp(frac, exp, dtype=ftype)
+ f = np.ldexp(ftype(frac), exp)
+ assert f.dtype == ftype
n, d = f.as_integer_ratio()
try:
diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py
index 64ecb3780..a47f1df49 100644
--- a/numpy/core/tests/test_ufunc.py
+++ b/numpy/core/tests/test_ufunc.py
@@ -457,6 +457,34 @@ class TestUfunc:
float_dtype = type(np.dtype(np.float64))
np.add(3, 4, signature=(float_dtype, float_dtype, None))
+ @pytest.mark.parametrize("casting", ["unsafe", "same_kind", "safe"])
+ def test_partial_signature_mismatch(self, casting):
+ # If the second argument matches already, no need to specify it:
+ res = np.ldexp(np.float32(1.), np.int_(2), dtype="d")
+ assert res.dtype == "d"
+ res = np.ldexp(np.float32(1.), np.int_(2), signature=(None, None, "d"))
+ assert res.dtype == "d"
+
+ # ldexp only has a loop for long input as second argument, overriding
+ # the output cannot help with that (no matter the casting)
+ with pytest.raises(TypeError):
+ np.ldexp(1., np.uint64(3), dtype="d")
+ with pytest.raises(TypeError):
+ np.ldexp(1., np.uint64(3), signature=(None, None, "d"))
+
+ def test_use_output_signature_for_all_arguments(self):
+ # Test that providing only `dtype=` or `signature=(None, None, dtype)`
+ # is sufficient if falling back to a homogeneous signature works.
+ # In this case, the `intp, intp -> intp` loop is chosen.
+ res = np.power(1.5, 2.8, dtype=np.intp, casting="unsafe")
+ assert res == 1 # the cast happens first.
+ res = np.power(1.5, 2.8, signature=(None, None, np.intp),
+ casting="unsafe")
+ assert res == 1
+ with pytest.raises(TypeError):
+ # the unsafe casting would normally cause errors though:
+ np.power(1.5, 2.8, dtype=np.intp)
+
def test_signature_errors(self):
with pytest.raises(TypeError,
match="the signature object to ufunc must be a string or"):
diff --git a/numpy/lib/index_tricks.pyi b/numpy/lib/index_tricks.pyi
index e486fe8f2..a3bfef6b6 100644
--- a/numpy/lib/index_tricks.pyi
+++ b/numpy/lib/index_tricks.pyi
@@ -33,7 +33,7 @@ from numpy.typing import (
ArrayLike,
_NestedSequence,
_RecursiveSequence,
- _ArrayND,
+ NDArray,
_ArrayLikeInt,
# DTypes
@@ -68,7 +68,7 @@ def unravel_index(
indices: _ArrayLikeInt,
shape: _ShapeLike,
order: _OrderCF = ...
-) -> Tuple[_ArrayND[intp], ...]: ...
+) -> Tuple[NDArray[intp], ...]: ...
@overload
def ravel_multi_index( # type: ignore[misc]
@@ -83,24 +83,24 @@ def ravel_multi_index(
dims: _ShapeLike,
mode: Union[_ModeKind, Tuple[_ModeKind, ...]] = ...,
order: _OrderCF = ...
-) -> _ArrayND[intp]: ...
+) -> NDArray[intp]: ...
@overload
def ix_(*args: _NestedSequence[_SupportsDType[_DType]]) -> Tuple[ndarray[Any, _DType], ...]: ...
@overload
-def ix_(*args: _NestedSequence[str]) -> Tuple[_ArrayND[str_], ...]: ...
+def ix_(*args: _NestedSequence[str]) -> Tuple[NDArray[str_], ...]: ...
@overload
-def ix_(*args: _NestedSequence[bytes]) -> Tuple[_ArrayND[bytes_], ...]: ...
+def ix_(*args: _NestedSequence[bytes]) -> Tuple[NDArray[bytes_], ...]: ...
@overload
-def ix_(*args: _NestedSequence[bool]) -> Tuple[_ArrayND[bool_], ...]: ...
+def ix_(*args: _NestedSequence[bool]) -> Tuple[NDArray[bool_], ...]: ...
@overload
-def ix_(*args: _NestedSequence[int]) -> Tuple[_ArrayND[int_], ...]: ...
+def ix_(*args: _NestedSequence[int]) -> Tuple[NDArray[int_], ...]: ...
@overload
-def ix_(*args: _NestedSequence[float]) -> Tuple[_ArrayND[float_], ...]: ...
+def ix_(*args: _NestedSequence[float]) -> Tuple[NDArray[float_], ...]: ...
@overload
-def ix_(*args: _NestedSequence[complex]) -> Tuple[_ArrayND[complex_], ...]: ...
+def ix_(*args: _NestedSequence[complex]) -> Tuple[NDArray[complex_], ...]: ...
@overload
-def ix_(*args: _RecursiveSequence) -> Tuple[_ArrayND[Any], ...]: ...
+def ix_(*args: _RecursiveSequence) -> Tuple[NDArray[Any], ...]: ...
class nd_grid(Generic[_BoolType]):
sparse: _BoolType
@@ -109,12 +109,12 @@ class nd_grid(Generic[_BoolType]):
def __getitem__(
self: nd_grid[Literal[False]],
key: Union[slice, Sequence[slice]],
- ) -> _ArrayND[Any]: ...
+ ) -> NDArray[Any]: ...
@overload
def __getitem__(
self: nd_grid[Literal[True]],
key: Union[slice, Sequence[slice]],
- ) -> List[_ArrayND[Any]]: ...
+ ) -> List[NDArray[Any]]: ...
class MGridClass(nd_grid[Literal[False]]):
def __init__(self) -> None: ...
@@ -142,7 +142,7 @@ class AxisConcatenator:
@overload
def concatenate( # type: ignore[misc]
*a: ArrayLike, axis: SupportsIndex = ..., out: None = ...
- ) -> _ArrayND[Any]: ...
+ ) -> NDArray[Any]: ...
@staticmethod
@overload
def concatenate(
@@ -188,7 +188,7 @@ index_exp: IndexExpression[Literal[True]]
s_: IndexExpression[Literal[False]]
def fill_diagonal(a: ndarray[Any, Any], val: Any, wrap: bool = ...) -> None: ...
-def diag_indices(n: int, ndim: int = ...) -> Tuple[_ArrayND[int_], ...]: ...
-def diag_indices_from(arr: ArrayLike) -> Tuple[_ArrayND[int_], ...]: ...
+def diag_indices(n: int, ndim: int = ...) -> Tuple[NDArray[int_], ...]: ...
+def diag_indices_from(arr: ArrayLike) -> Tuple[NDArray[int_], ...]: ...
# NOTE: see `numpy/__init__.pyi` for `ndenumerate` and `ndindex`
diff --git a/numpy/lib/ufunclike.pyi b/numpy/lib/ufunclike.pyi
index e97383af8..03f08ebff 100644
--- a/numpy/lib/ufunclike.pyi
+++ b/numpy/lib/ufunclike.pyi
@@ -2,7 +2,7 @@ from typing import Any, overload, TypeVar, List, Union
from numpy import floating, bool_, object_, ndarray
from numpy.typing import (
- _ArrayND,
+ NDArray,
_FloatLike_co,
_ArrayLikeFloat_co,
_ArrayLikeObject_co,
@@ -21,12 +21,12 @@ def fix( # type: ignore[misc]
def fix(
x: _ArrayLikeFloat_co,
out: None = ...,
-) -> _ArrayND[floating[Any]]: ...
+) -> NDArray[floating[Any]]: ...
@overload
def fix(
x: _ArrayLikeObject_co,
out: None = ...,
-) -> _ArrayND[object_]: ...
+) -> NDArray[object_]: ...
@overload
def fix(
x: Union[_ArrayLikeFloat_co, _ArrayLikeObject_co],
@@ -42,7 +42,7 @@ def isposinf( # type: ignore[misc]
def isposinf(
x: _ArrayLikeFloat_co,
out: None = ...,
-) -> _ArrayND[bool_]: ...
+) -> NDArray[bool_]: ...
@overload
def isposinf(
x: _ArrayLikeFloat_co,
@@ -58,7 +58,7 @@ def isneginf( # type: ignore[misc]
def isneginf(
x: _ArrayLikeFloat_co,
out: None = ...,
-) -> _ArrayND[bool_]: ...
+) -> NDArray[bool_]: ...
@overload
def isneginf(
x: _ArrayLikeFloat_co,
diff --git a/numpy/ma/tests/test_mrecords.py b/numpy/ma/tests/test_mrecords.py
index c2f859273..27df519d2 100644
--- a/numpy/ma/tests/test_mrecords.py
+++ b/numpy/ma/tests/test_mrecords.py
@@ -405,7 +405,7 @@ class TestMRecordsImport:
for (f, l) in zip(('a', 'b', 'c'), (_a, _b, _c)):
assert_equal(getattr(mrec, f)._mask, l._mask)
# One record only
- _x = ma.array([1, 1.1, 'one'], mask=[1, 0, 0],)
+ _x = ma.array([1, 1.1, 'one'], mask=[1, 0, 0], dtype=object)
assert_equal_records(fromarrays(_x, dtype=mrec.dtype), mrec[0])
def test_fromrecords(self):
diff --git a/numpy/typing/__init__.py b/numpy/typing/__init__.py
index a2d4c60fb..4f0dc0cf1 100644
--- a/numpy/typing/__init__.py
+++ b/numpy/typing/__init__.py
@@ -339,7 +339,6 @@ from ._array_like import (
_NestedSequence,
_RecursiveSequence,
_SupportsArray,
- _ArrayND,
_ArrayLikeInt,
_ArrayLikeBool_co,
_ArrayLikeUInt_co,
@@ -354,6 +353,10 @@ from ._array_like import (
_ArrayLikeStr_co,
_ArrayLikeBytes_co,
)
+from ._generic_alias import (
+ NDArray as NDArray,
+ _GenericAlias,
+)
if __doc__ is not None:
from ._add_docstring import _docstrings
diff --git a/numpy/typing/_add_docstring.py b/numpy/typing/_add_docstring.py
index 8e39fe2c6..34dbdb0c6 100644
--- a/numpy/typing/_add_docstring.py
+++ b/numpy/typing/_add_docstring.py
@@ -3,14 +3,32 @@
import re
import textwrap
+from ._generic_alias import NDArray
+
_docstrings_list = []
-def add_newdoc(name, value, doc):
+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():
+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 ")
@@ -93,4 +111,33 @@ add_newdoc('DTypeLike', 'typing.Union[...]',
""")
+add_newdoc('NDArray', repr(NDArray),
+ """
+ A :term:`generic <generic type>` version of
+ `np.ndarray[Any, np.dtype[~ScalarType]] <numpy.ndarray>`.
+
+ Can be used during runtime for typing arrays with a given dtype
+ and unspecified shape.
+
+ Examples
+ --------
+ .. code-block:: python
+
+ >>> import numpy as np
+ >>> import numpy.typing as npt
+
+ >>> print(npt.NDArray)
+ numpy.ndarray[typing.Any, numpy.dtype[~ScalarType]]
+
+ >>> print(npt.NDArray[np.float64])
+ numpy.ndarray[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/numpy/typing/_array_like.py b/numpy/typing/_array_like.py
index 582d3db9a..9f57b2295 100644
--- a/numpy/typing/_array_like.py
+++ b/numpy/typing/_array_like.py
@@ -129,8 +129,3 @@ _ArrayLikeInt = _ArrayLike[
"dtype[integer[Any]]",
int,
]
-
-if TYPE_CHECKING:
- _ArrayND = ndarray[Any, dtype[_ScalarType]]
-else:
- _ArrayND = Any
diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py
index 30c210b62..d9cb0f157 100644
--- a/numpy/typing/_callable.py
+++ b/numpy/typing/_callable.py
@@ -47,7 +47,8 @@ from ._scalars import (
_NumberLike_co,
)
from . import NBitBase
-from ._array_like import ArrayLike, _ArrayND
+from ._array_like import ArrayLike
+from ._generic_alias import NDArray
if sys.version_info >= (3, 8):
from typing import Protocol
@@ -336,7 +337,7 @@ if TYPE_CHECKING or HAVE_PROTOCOL:
@overload
def __call__(self, __other: _T1) -> bool_: ...
@overload
- def __call__(self, __other: _T2) -> _ArrayND[bool_]: ...
+ def __call__(self, __other: _T2) -> NDArray[bool_]: ...
else:
_BoolOp = Any
diff --git a/numpy/typing/_generic_alias.py b/numpy/typing/_generic_alias.py
new file mode 100644
index 000000000..f98fca62e
--- /dev/null
+++ b/numpy/typing/_generic_alias.py
@@ -0,0 +1,207 @@
+from __future__ import annotations
+
+import sys
+import types
+from typing import (
+ Any,
+ ClassVar,
+ FrozenSet,
+ Generator,
+ Iterable,
+ Iterator,
+ List,
+ NoReturn,
+ Tuple,
+ Type,
+ TypeVar,
+ TYPE_CHECKING,
+)
+
+import numpy as np
+
+__all__ = ["_GenericAlias", "NDArray"]
+
+_T = TypeVar("_T", bound="_GenericAlias")
+
+
+def _to_str(obj: object) -> str:
+ """Helper function for `_GenericAlias.__repr__`."""
+ if obj is Ellipsis:
+ return '...'
+ elif isinstance(obj, type) and not isinstance(obj, _GENERIC_ALIAS_TYPE):
+ if obj.__module__ == 'builtins':
+ return obj.__qualname__
+ else:
+ return f'{obj.__module__}.{obj.__qualname__}'
+ else:
+ return repr(obj)
+
+
+def _parse_parameters(args: Iterable[Any]) -> Generator[TypeVar, None, None]:
+ """Search for all typevars and typevar-containing objects in `args`.
+
+ Helper function for `_GenericAlias.__init__`.
+
+ """
+ for i in args:
+ if hasattr(i, "__parameters__"):
+ yield from i.__parameters__
+ elif isinstance(i, TypeVar):
+ yield i
+
+
+def _reconstruct_alias(alias: _T, parameters: Iterator[TypeVar]) -> _T:
+ """Recursivelly replace all typevars with those from `parameters`.
+
+ Helper function for `_GenericAlias.__getitem__`.
+
+ """
+ args = []
+ for i in alias.__args__:
+ if isinstance(i, TypeVar):
+ value: Any = next(parameters)
+ elif isinstance(i, _GenericAlias):
+ value = _reconstruct_alias(i, parameters)
+ elif hasattr(i, "__parameters__"):
+ value = i[next(parameters)]
+ else:
+ value = i
+ args.append(value)
+
+ cls = type(alias)
+ return cls(alias.__origin__, tuple(args))
+
+
+class _GenericAlias:
+ """A python-based backport of the `types.GenericAlias` class.
+
+ E.g. for ``t = list[int]``, ``t.__origin__`` is ``list`` and
+ ``t.__args__`` is ``(int,)``.
+
+ See Also
+ --------
+ :pep:`585`
+ The PEP responsible for introducing `types.GenericAlias`.
+
+ """
+
+ __slots__ = ("__weakref__", "_origin", "_args", "_parameters", "_hash")
+
+ @property
+ def __origin__(self) -> type:
+ return super().__getattribute__("_origin")
+
+ @property
+ def __args__(self) -> Tuple[Any, ...]:
+ return super().__getattribute__("_args")
+
+ @property
+ def __parameters__(self) -> Tuple[TypeVar, ...]:
+ """Type variables in the ``GenericAlias``."""
+ return super().__getattribute__("_parameters")
+
+ def __init__(self, origin: type, args: Any) -> None:
+ self._origin = origin
+ self._args = args if isinstance(args, tuple) else (args,)
+ self._parameters = tuple(_parse_parameters(args))
+
+ @property
+ def __call__(self) -> type:
+ return self.__origin__
+
+ def __reduce__(self: _T) -> Tuple[Type[_T], Tuple[type, Tuple[Any, ...]]]:
+ cls = type(self)
+ return cls, (self.__origin__, self.__args__)
+
+ def __mro_entries__(self, bases: Iterable[object]) -> Tuple[type]:
+ return (self.__origin__,)
+
+ def __dir__(self) -> List[str]:
+ """Implement ``dir(self)``."""
+ cls = type(self)
+ dir_origin = set(dir(self.__origin__))
+ return sorted(cls._ATTR_EXCEPTIONS | dir_origin)
+
+ def __hash__(self) -> int:
+ """Return ``hash(self)``."""
+ # Attempt to use the cached hash
+ try:
+ return super().__getattribute__("_hash")
+ except AttributeError:
+ self._hash: int = hash(self.__origin__) ^ hash(self.__args__)
+ return super().__getattribute__("_hash")
+
+ def __instancecheck__(self, obj: object) -> NoReturn:
+ """Check if an `obj` is an instance."""
+ raise TypeError("isinstance() argument 2 cannot be a "
+ "parameterized generic")
+
+ def __subclasscheck__(self, cls: type) -> NoReturn:
+ """Check if a `cls` is a subclass."""
+ raise TypeError("issubclass() argument 2 cannot be a "
+ "parameterized generic")
+
+ def __repr__(self) -> str:
+ """Return ``repr(self)``."""
+ args = ", ".join(_to_str(i) for i in self.__args__)
+ origin = _to_str(self.__origin__)
+ return f"{origin}[{args}]"
+
+ def __getitem__(self: _T, key: Any) -> _T:
+ """Return ``self[key]``."""
+ key_tup = key if isinstance(key, tuple) else (key,)
+
+ if len(self.__parameters__) == 0:
+ raise TypeError(f"There are no type variables left in {self}")
+ elif len(key_tup) > len(self.__parameters__):
+ raise TypeError(f"Too many arguments for {self}")
+ elif len(key_tup) < len(self.__parameters__):
+ raise TypeError(f"Too few arguments for {self}")
+
+ key_iter = iter(key_tup)
+ return _reconstruct_alias(self, key_iter)
+
+ def __eq__(self, value: object) -> bool:
+ """Return ``self == value``."""
+ if not isinstance(value, _GENERIC_ALIAS_TYPE):
+ return NotImplemented
+ return (
+ self.__origin__ == value.__origin__ and
+ self.__args__ == value.__args__
+ )
+
+ _ATTR_EXCEPTIONS: ClassVar[FrozenSet[str]] = frozenset({
+ "__origin__",
+ "__args__",
+ "__parameters__",
+ "__mro_entries__",
+ "__reduce__",
+ "__reduce_ex__",
+ })
+
+ def __getattribute__(self, name: str) -> Any:
+ """Return ``getattr(self, name)``."""
+ # Pull the attribute from `__origin__` unless its
+ # name is in `_ATTR_EXCEPTIONS`
+ cls = type(self)
+ if name in cls._ATTR_EXCEPTIONS:
+ return super().__getattribute__(name)
+ return getattr(self.__origin__, name)
+
+
+# See `_GenericAlias.__eq__`
+if sys.version_info >= (3, 9):
+ _GENERIC_ALIAS_TYPE = (_GenericAlias, types.GenericAlias)
+else:
+ _GENERIC_ALIAS_TYPE = (_GenericAlias,)
+
+ScalarType = TypeVar("ScalarType", bound=np.generic)
+
+if TYPE_CHECKING:
+ NDArray = np.ndarray[Any, np.dtype[ScalarType]]
+elif sys.version_info >= (3, 9):
+ _DType = types.GenericAlias(np.dtype, (ScalarType,))
+ NDArray = types.GenericAlias(np.ndarray, (Any, _DType))
+else:
+ _DType = _GenericAlias(np.dtype, (ScalarType,))
+ NDArray = _GenericAlias(np.ndarray, (Any, _DType))
diff --git a/numpy/typing/tests/data/fail/datasource.py b/numpy/typing/tests/data/fail/datasource.py
new file mode 100644
index 000000000..345277d45
--- /dev/null
+++ b/numpy/typing/tests/data/fail/datasource.py
@@ -0,0 +1,15 @@
+from pathlib import Path
+import numpy as np
+
+path: Path
+d1: np.DataSource
+
+d1.abspath(path) # E: incompatible type
+d1.abspath(b"...") # E: incompatible type
+
+d1.exists(path) # E: incompatible type
+d1.exists(b"...") # E: incompatible type
+
+d1.open(path, "r") # E: incompatible type
+d1.open(b"...", encoding="utf8") # E: incompatible type
+d1.open(None, newline="/n") # E: incompatible type
diff --git a/numpy/typing/tests/data/fail/ndarray_misc.py b/numpy/typing/tests/data/fail/ndarray_misc.py
index 1e1496bfe..653b9267b 100644
--- a/numpy/typing/tests/data/fail/ndarray_misc.py
+++ b/numpy/typing/tests/data/fail/ndarray_misc.py
@@ -6,9 +6,13 @@ function-based counterpart in `../from_numeric.py`.
"""
+from typing import Any
import numpy as np
f8: np.float64
+AR_f8: np.ndarray[Any, np.dtype[np.float64]]
+AR_M: np.ndarray[Any, np.dtype[np.datetime64]]
+AR_b: np.ndarray[Any, np.dtype[np.bool_]]
f8.argpartition(0) # E: has no attribute
f8.diagonal() # E: has no attribute
@@ -19,3 +23,8 @@ f8.put(0, 2) # E: has no attribute
f8.setfield(2, np.float64) # E: has no attribute
f8.sort() # E: has no attribute
f8.trace() # E: has no attribute
+
+AR_M.__int__() # E: Invalid self argument
+AR_M.__float__() # E: Invalid self argument
+AR_M.__complex__() # E: Invalid self argument
+AR_b.__index__() # E: Invalid self argument
diff --git a/numpy/typing/tests/data/pass/multiarray.py b/numpy/typing/tests/data/pass/multiarray.py
new file mode 100644
index 000000000..e2b5d16a0
--- /dev/null
+++ b/numpy/typing/tests/data/pass/multiarray.py
@@ -0,0 +1,37 @@
+from __future__ import annotations
+
+from typing import Any
+import numpy as np
+
+AR_f8: np.ndarray[Any, np.dtype[np.float64]] = np.array([1.0])
+AR_i8: np.ndarray[Any, np.dtype[np.int_]] = np.array([1])
+
+b_f8 = np.broadcast(AR_f8)
+b_i8_f8_f8 = np.broadcast(AR_i8, AR_f8, AR_f8)
+
+next(b_f8)
+next(b_i8_f8_f8)
+
+b_f8.reset()
+b_i8_f8_f8.reset()
+
+b_f8.index
+b_i8_f8_f8.index
+
+b_f8.iters
+b_i8_f8_f8.iters
+
+b_f8.nd
+b_i8_f8_f8.nd
+
+b_f8.ndim
+b_i8_f8_f8.ndim
+
+b_f8.numiter
+b_i8_f8_f8.numiter
+
+b_f8.shape
+b_i8_f8_f8.shape
+
+b_f8.size
+b_i8_f8_f8.size
diff --git a/numpy/typing/tests/data/pass/ndarray_misc.py b/numpy/typing/tests/data/pass/ndarray_misc.py
index ba10ce974..62024603c 100644
--- a/numpy/typing/tests/data/pass/ndarray_misc.py
+++ b/numpy/typing/tests/data/pass/ndarray_misc.py
@@ -8,7 +8,9 @@ function-based counterpart in `../from_numeric.py`.
from __future__ import annotations
+import operator
from typing import cast, Any
+
import numpy as np
class SubClass(np.ndarray): ...
@@ -162,3 +164,22 @@ void.setfield(10, np.float64)
A.item(0)
C.item(0)
+
+A.ravel()
+C.ravel()
+
+A.flatten()
+C.flatten()
+
+A.reshape(1)
+C.reshape(3)
+
+int(np.array(1.0, dtype=np.float64))
+int(np.array("1", dtype=np.str_))
+
+float(np.array(1.0, dtype=np.float64))
+float(np.array("1", dtype=np.str_))
+
+complex(np.array(1.0, dtype=np.float64))
+
+operator.index(np.array(1, dtype=np.int64))
diff --git a/numpy/typing/tests/data/pass/scalars.py b/numpy/typing/tests/data/pass/scalars.py
index f7965e1c5..b258db49f 100644
--- a/numpy/typing/tests/data/pass/scalars.py
+++ b/numpy/typing/tests/data/pass/scalars.py
@@ -4,6 +4,14 @@ import datetime as dt
import pytest
import numpy as np
+b = np.bool_()
+u8 = np.uint64()
+i8 = np.int64()
+f8 = np.float64()
+c16 = np.complex128()
+U = np.str_()
+S = np.bytes_()
+
# Construction
class D:
@@ -205,18 +213,42 @@ np.clongdouble()
np.clongfloat()
np.longcomplex()
-np.bool_().item()
-np.int_().item()
-np.uint64().item()
-np.float32().item()
-np.complex128().item()
-np.str_().item()
-np.bytes_().item()
-
-np.bool_().tolist()
-np.int_().tolist()
-np.uint64().tolist()
-np.float32().tolist()
-np.complex128().tolist()
-np.str_().tolist()
-np.bytes_().tolist()
+b.item()
+i8.item()
+u8.item()
+f8.item()
+c16.item()
+U.item()
+S.item()
+
+b.tolist()
+i8.tolist()
+u8.tolist()
+f8.tolist()
+c16.tolist()
+U.tolist()
+S.tolist()
+
+b.ravel()
+i8.ravel()
+u8.ravel()
+f8.ravel()
+c16.ravel()
+U.ravel()
+S.ravel()
+
+b.flatten()
+i8.flatten()
+u8.flatten()
+f8.flatten()
+c16.flatten()
+U.flatten()
+S.flatten()
+
+b.reshape(1)
+i8.reshape(1)
+u8.reshape(1)
+f8.reshape(1)
+c16.reshape(1)
+U.reshape(1)
+S.reshape(1)
diff --git a/numpy/typing/tests/data/reveal/datasource.py b/numpy/typing/tests/data/reveal/datasource.py
new file mode 100644
index 000000000..245ac7649
--- /dev/null
+++ b/numpy/typing/tests/data/reveal/datasource.py
@@ -0,0 +1,21 @@
+from pathlib import Path
+import numpy as np
+
+path1: Path
+path2: str
+
+d1 = np.DataSource(path1)
+d2 = np.DataSource(path2)
+d3 = np.DataSource(None)
+
+reveal_type(d1.abspath("...")) # E: str
+reveal_type(d2.abspath("...")) # E: str
+reveal_type(d3.abspath("...")) # E: str
+
+reveal_type(d1.exists("...")) # E: bool
+reveal_type(d2.exists("...")) # E: bool
+reveal_type(d3.exists("...")) # E: bool
+
+reveal_type(d1.open("...", "r")) # E: IO[Any]
+reveal_type(d2.open("...", encoding="utf8")) # E: IO[Any]
+reveal_type(d3.open("...", newline="/n")) # E: IO[Any]
diff --git a/numpy/typing/tests/data/reveal/multiarray.py b/numpy/typing/tests/data/reveal/multiarray.py
new file mode 100644
index 000000000..33e9ede7c
--- /dev/null
+++ b/numpy/typing/tests/data/reveal/multiarray.py
@@ -0,0 +1,35 @@
+from typing import Any
+import numpy as np
+
+AR_f8: np.ndarray[Any, np.dtype[np.float64]]
+AR_i8: np.ndarray[Any, np.dtype[np.int64]]
+
+b_f8 = np.broadcast(AR_f8)
+b_i8_f8_f8 = np.broadcast(AR_i8, AR_f8, AR_f8)
+
+reveal_type(next(b_f8)) # E: tuple[Any]
+reveal_type(next(b_i8_f8_f8)) # E: tuple[Any]
+
+reveal_type(b_f8.reset()) # E: None
+reveal_type(b_i8_f8_f8.reset()) # E: None
+
+reveal_type(b_f8.index) # E: int
+reveal_type(b_i8_f8_f8.index) # E: int
+
+reveal_type(b_f8.iters) # E: tuple[numpy.flatiter[Any]]
+reveal_type(b_i8_f8_f8.iters) # E: tuple[numpy.flatiter[Any]]
+
+reveal_type(b_f8.nd) # E: int
+reveal_type(b_i8_f8_f8.nd) # E: int
+
+reveal_type(b_f8.ndim) # E: int
+reveal_type(b_i8_f8_f8.ndim) # E: int
+
+reveal_type(b_f8.numiter) # E: int
+reveal_type(b_i8_f8_f8.numiter) # E: int
+
+reveal_type(b_f8.shape) # E: tuple[builtins.int]
+reveal_type(b_i8_f8_f8.shape) # E: tuple[builtins.int]
+
+reveal_type(b_f8.size) # E: int
+reveal_type(b_i8_f8_f8.size) # E: int
diff --git a/numpy/typing/tests/data/reveal/ndarray_misc.py b/numpy/typing/tests/data/reveal/ndarray_misc.py
index 8c45eb6f3..ecc322251 100644
--- a/numpy/typing/tests/data/reveal/ndarray_misc.py
+++ b/numpy/typing/tests/data/reveal/ndarray_misc.py
@@ -6,14 +6,17 @@ function-based counterpart in `../from_numeric.py`.
"""
+import operator
from typing import Any
+
import numpy as np
class SubClass(np.ndarray): ...
f8: np.float64
-AR_f8: np.ndarray[Any, np.dtype[np.float64]]
B: SubClass
+AR_f8: np.ndarray[Any, np.dtype[np.float64]]
+AR_i8: np.ndarray[Any, np.dtype[np.int64]]
AR_U: np.ndarray[Any, np.dtype[np.str_]]
reveal_type(f8.all()) # E: numpy.bool_
@@ -137,19 +140,40 @@ reveal_type(AR_f8.var(axis=0)) # E: Any
reveal_type(AR_f8.var(keepdims=True)) # E: Any
reveal_type(AR_f8.var(out=B)) # E: SubClass
-reveal_type(AR_f8.argpartition([0])) # E: numpy.ndarray[Any, Any]
+reveal_type(AR_f8.argpartition([0])) # E: numpy.ndarray[Any, numpy.dtype[{intp}]]
reveal_type(AR_f8.diagonal()) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
-reveal_type(AR_f8.dot(1)) # E: Any
+reveal_type(AR_f8.dot(1)) # E: numpy.ndarray[Any, Any]
+reveal_type(AR_f8.dot([1])) # E: Any
reveal_type(AR_f8.dot(1, out=B)) # E: SubClass
-reveal_type(AR_f8.nonzero()) # E: tuple[numpy.ndarray[Any, Any]]
+reveal_type(AR_f8.nonzero()) # E: tuple[numpy.ndarray[Any, numpy.dtype[{intp}]]]
-reveal_type(AR_f8.searchsorted([1])) # E: numpy.ndarray[Any, Any]
+reveal_type(AR_f8.searchsorted(1)) # E: {intp}
+reveal_type(AR_f8.searchsorted([1])) # E: numpy.ndarray[Any, numpy.dtype[{intp}]]
reveal_type(AR_f8.trace()) # E: Any
reveal_type(AR_f8.trace(out=B)) # E: SubClass
reveal_type(AR_f8.item()) # E: float
reveal_type(AR_U.item()) # E: str
+
+reveal_type(AR_f8.ravel()) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(AR_U.ravel()) # E: numpy.ndarray[Any, numpy.dtype[numpy.str_]]
+
+reveal_type(AR_f8.flatten()) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(AR_U.flatten()) # E: numpy.ndarray[Any, numpy.dtype[numpy.str_]]
+
+reveal_type(AR_f8.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(AR_U.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[numpy.str_]]
+
+reveal_type(int(AR_f8)) # E: int
+reveal_type(int(AR_U)) # E: int
+
+reveal_type(float(AR_f8)) # E: float
+reveal_type(float(AR_U)) # E: float
+
+reveal_type(complex(AR_f8)) # E: complex
+
+reveal_type(operator.index(AR_i8)) # E: int
diff --git a/numpy/typing/tests/data/reveal/scalars.py b/numpy/typing/tests/data/reveal/scalars.py
index f50c46c43..d98388422 100644
--- a/numpy/typing/tests/data/reveal/scalars.py
+++ b/numpy/typing/tests/data/reveal/scalars.py
@@ -1,28 +1,35 @@
import numpy as np
-x = np.complex64(3 + 2j)
+b: np.bool_
+u8: np.uint64
+i8: np.int64
+f8: np.float64
+c8: np.complex64
+c16: np.complex128
+U: np.str_
+S: np.bytes_
-reveal_type(x.real) # E: {float32}
-reveal_type(x.imag) # E: {float32}
+reveal_type(c8.real) # E: {float32}
+reveal_type(c8.imag) # E: {float32}
-reveal_type(x.real.real) # E: {float32}
-reveal_type(x.real.imag) # E: {float32}
+reveal_type(c8.real.real) # E: {float32}
+reveal_type(c8.real.imag) # E: {float32}
-reveal_type(x.itemsize) # E: int
-reveal_type(x.shape) # E: Tuple[]
-reveal_type(x.strides) # E: Tuple[]
+reveal_type(c8.itemsize) # E: int
+reveal_type(c8.shape) # E: Tuple[]
+reveal_type(c8.strides) # E: Tuple[]
-reveal_type(x.ndim) # E: Literal[0]
-reveal_type(x.size) # E: Literal[1]
+reveal_type(c8.ndim) # E: Literal[0]
+reveal_type(c8.size) # E: Literal[1]
-reveal_type(x.squeeze()) # E: {complex64}
-reveal_type(x.byteswap()) # E: {complex64}
-reveal_type(x.transpose()) # E: {complex64}
+reveal_type(c8.squeeze()) # E: {complex64}
+reveal_type(c8.byteswap()) # E: {complex64}
+reveal_type(c8.transpose()) # E: {complex64}
-reveal_type(x.dtype) # E: numpy.dtype[{complex64}]
+reveal_type(c8.dtype) # E: numpy.dtype[{complex64}]
-reveal_type(np.complex64().real) # E: {float32}
-reveal_type(np.complex128().imag) # E: {float64}
+reveal_type(c8.real) # E: {float32}
+reveal_type(c16.imag) # E: {float64}
reveal_type(np.unicode_('foo')) # E: numpy.str_
reveal_type(np.str0('foo')) # E: numpy.str_
@@ -68,18 +75,42 @@ reveal_type(np.clongdouble()) # E: {clongdouble}
reveal_type(np.clongfloat()) # E: {clongdouble}
reveal_type(np.longcomplex()) # E: {clongdouble}
-reveal_type(np.bool_().item()) # E: bool
-reveal_type(np.int_().item()) # E: int
-reveal_type(np.uint64().item()) # E: int
-reveal_type(np.float32().item()) # E: float
-reveal_type(np.complex128().item()) # E: complex
-reveal_type(np.str_().item()) # E: str
-reveal_type(np.bytes_().item()) # E: bytes
-
-reveal_type(np.bool_().tolist()) # E: bool
-reveal_type(np.int_().tolist()) # E: int
-reveal_type(np.uint64().tolist()) # E: int
-reveal_type(np.float32().tolist()) # E: float
-reveal_type(np.complex128().tolist()) # E: complex
-reveal_type(np.str_().tolist()) # E: str
-reveal_type(np.bytes_().tolist()) # E: bytes
+reveal_type(b.item()) # E: bool
+reveal_type(i8.item()) # E: int
+reveal_type(u8.item()) # E: int
+reveal_type(f8.item()) # E: float
+reveal_type(c16.item()) # E: complex
+reveal_type(U.item()) # E: str
+reveal_type(S.item()) # E: bytes
+
+reveal_type(b.tolist()) # E: bool
+reveal_type(i8.tolist()) # E: int
+reveal_type(u8.tolist()) # E: int
+reveal_type(f8.tolist()) # E: float
+reveal_type(c16.tolist()) # E: complex
+reveal_type(U.tolist()) # E: str
+reveal_type(S.tolist()) # E: bytes
+
+reveal_type(b.ravel()) # E: numpy.ndarray[Any, numpy.dtype[numpy.bool_]]
+reveal_type(i8.ravel()) # E: numpy.ndarray[Any, numpy.dtype[{int64}]]
+reveal_type(u8.ravel()) # E: numpy.ndarray[Any, numpy.dtype[{uint64}]]
+reveal_type(f8.ravel()) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(c16.ravel()) # E: numpy.ndarray[Any, numpy.dtype[{complex128}]]
+reveal_type(U.ravel()) # E: numpy.ndarray[Any, numpy.dtype[numpy.str_]]
+reveal_type(S.ravel()) # E: numpy.ndarray[Any, numpy.dtype[numpy.bytes_]]
+
+reveal_type(b.flatten()) # E: numpy.ndarray[Any, numpy.dtype[numpy.bool_]]
+reveal_type(i8.flatten()) # E: numpy.ndarray[Any, numpy.dtype[{int64}]]
+reveal_type(u8.flatten()) # E: numpy.ndarray[Any, numpy.dtype[{uint64}]]
+reveal_type(f8.flatten()) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(c16.flatten()) # E: numpy.ndarray[Any, numpy.dtype[{complex128}]]
+reveal_type(U.flatten()) # E: numpy.ndarray[Any, numpy.dtype[numpy.str_]]
+reveal_type(S.flatten()) # E: numpy.ndarray[Any, numpy.dtype[numpy.bytes_]]
+
+reveal_type(b.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[numpy.bool_]]
+reveal_type(i8.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[{int64}]]
+reveal_type(u8.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[{uint64}]]
+reveal_type(f8.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[{float64}]]
+reveal_type(c16.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[{complex128}]]
+reveal_type(U.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[numpy.str_]]
+reveal_type(S.reshape(1)) # E: numpy.ndarray[Any, numpy.dtype[numpy.bytes_]]
diff --git a/numpy/typing/tests/test_generic_alias.py b/numpy/typing/tests/test_generic_alias.py
new file mode 100644
index 000000000..13072051a
--- /dev/null
+++ b/numpy/typing/tests/test_generic_alias.py
@@ -0,0 +1,112 @@
+from __future__ import annotations
+
+import sys
+import types
+import pickle
+import weakref
+from typing import TypeVar, Any, Callable, Tuple, Type, Union
+
+import pytest
+import numpy as np
+from numpy.typing._generic_alias import _GenericAlias
+
+ScalarType = TypeVar("ScalarType", bound=np.generic)
+DType = _GenericAlias(np.dtype, (ScalarType,))
+NDArray = _GenericAlias(np.ndarray, (Any, DType))
+
+if sys.version_info >= (3, 9):
+ DType_ref = types.GenericAlias(np.dtype, (ScalarType,))
+ NDArray_ref = types.GenericAlias(np.ndarray, (Any, DType_ref))
+ FuncType = Callable[[Union[_GenericAlias, types.GenericAlias]], Any]
+else:
+ DType_ref = NotImplemented
+ NDArray_ref = NotImplemented
+ FuncType = Callable[[_GenericAlias], Any]
+
+GETATTR_NAMES = sorted(set(dir(np.ndarray)) - _GenericAlias._ATTR_EXCEPTIONS)
+
+BUFFER = np.array([1], dtype=np.int64)
+BUFFER.setflags(write=False)
+
+def _get_subclass_mro(base: type) -> Tuple[type, ...]:
+ class Subclass(base): # type: ignore[misc,valid-type]
+ pass
+ return Subclass.__mro__[1:]
+
+
+class TestGenericAlias:
+ """Tests for `numpy.typing._generic_alias._GenericAlias`."""
+
+ @pytest.mark.parametrize("name,func", [
+ ("__init__", lambda n: n),
+ ("__origin__", lambda n: n.__origin__),
+ ("__args__", lambda n: n.__args__),
+ ("__parameters__", lambda n: n.__parameters__),
+ ("__reduce__", lambda n: n.__reduce__()[1:]),
+ ("__reduce_ex__", lambda n: n.__reduce_ex__(1)[1:]),
+ ("__mro_entries__", lambda n: n.__mro_entries__([object])),
+ ("__hash__", lambda n: hash(n)),
+ ("__repr__", lambda n: repr(n)),
+ ("__getitem__", lambda n: n[np.float64]),
+ ("__getitem__", lambda n: n[ScalarType][np.float64]),
+ ("__getitem__", lambda n: n[Union[np.int64, ScalarType]][np.float64]),
+ ("__eq__", lambda n: n == n),
+ ("__ne__", lambda n: n != np.ndarray),
+ ("__dir__", lambda n: dir(n)),
+ ("__call__", lambda n: n((1,), np.int64, BUFFER)),
+ ("__call__", lambda n: n(shape=(1,), dtype=np.int64, buffer=BUFFER)),
+ ("subclassing", lambda n: _get_subclass_mro(n)),
+ ("pickle", lambda n: n == pickle.loads(pickle.dumps(n))),
+ ("__weakref__", lambda n: n == weakref.ref(n)()),
+ ])
+ def test_pass(self, name: str, func: FuncType) -> None:
+ """Compare `types.GenericAlias` with its numpy-based backport.
+
+ Checker whether ``func`` runs as intended and that both `GenericAlias`
+ and `_GenericAlias` return the same result.
+
+ """
+ value = func(NDArray)
+
+ if sys.version_info >= (3, 9):
+ value_ref = func(NDArray_ref)
+ assert value == value_ref
+
+ @pytest.mark.parametrize("name", GETATTR_NAMES)
+ def test_getattr(self, name: str) -> None:
+ """Test that `getattr` wraps around the underlying type,
+ aka ``__origin__``.
+
+ """
+ value = getattr(NDArray, name)
+ value_ref1 = getattr(np.ndarray, name)
+
+ if sys.version_info >= (3, 9):
+ value_ref2 = getattr(NDArray_ref, name)
+ assert value == value_ref1 == value_ref2
+ else:
+ assert value == value_ref1
+
+ @pytest.mark.parametrize("name,exc_type,func", [
+ ("__getitem__", TypeError, lambda n: n[()]),
+ ("__getitem__", TypeError, lambda n: n[Any, Any]),
+ ("__getitem__", TypeError, lambda n: n[Any][Any]),
+ ("isinstance", TypeError, lambda n: isinstance(np.array(1), n)),
+ ("issublass", TypeError, lambda n: issubclass(np.ndarray, n)),
+ ("setattr", AttributeError, lambda n: setattr(n, "__origin__", int)),
+ ("setattr", AttributeError, lambda n: setattr(n, "test", int)),
+ ("getattr", AttributeError, lambda n: getattr(n, "test")),
+ ])
+ def test_raise(
+ self,
+ name: str,
+ exc_type: Type[BaseException],
+ func: FuncType,
+ ) -> None:
+ """Test operations that are supposed to raise."""
+ with pytest.raises(exc_type):
+ func(NDArray)
+
+ if sys.version_info >= (3, 9):
+ with pytest.raises(exc_type):
+ func(NDArray_ref)