8000 ENH: Add dtype-support to the ufunc-based `ndarray` magic methods 4/4 by BvB93 · Pull Request #18417 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Add dtype-support to the ufunc-based ndarray magic methods 4/4 #18417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 6, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
8000 Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ENH: Add dtype-support to the (ufunc-based) ndarray inplace magic m…
…ethods
  • Loading branch information
Bas van Beek committed Mar 4, 2021
commit 2cc9e2994f14ccfb3cc276db08a9d632621fcb55
198 changes: 186 additions & 12 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from numpy.typing import (
_SupportsArray,
_NestedSequence,
_RecursiveSequence,
_SupportsArray,
_ArrayLikeBool_co,
_ArrayLikeUInt_co,
_ArrayLikeInt_co,
Expand Down Expand Up @@ -2202,18 +2203,191 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeType, _DType_co]):
) -> Any: ...

# `np.generic` does not support inplace operations
def __iadd__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __isub__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __imul__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __itruediv__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __ifloordiv__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __ipow__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __imod__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __ilshift__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __irshift__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __iand__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __ixor__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
def __ior__(self: _ArraySelf, other: ArrayLike) -> _ArraySelf: ...
@overload # type: ignore[misc]
def __iadd__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __iadd__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
@overload
def __iadd__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __iadd__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __iadd__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
@overload
def __iadd__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
@overload
def __iadd__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ...
@overload
def __iadd__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ...
@overload
def __iadd__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __iadd__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __isub__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __isub__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
def __isub__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __isub__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __isub__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
@overload
def __isub__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
@overload
def __isub__(self: _ArrayND[timedelta64], other: _ArrayLikeTD64_co) -> _ArrayND[timedelta64]: ...
@overload
def __isub__(self: _ArrayND[datetime64], other: _ArrayLikeTD64_co) -> _ArrayND[datetime64]: ...
@overload
def __isub__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __isub__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __imul__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __imul__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
@overload
def __imul__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __imul__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __imul__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
@overload
def __imul__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
@overload
def __imul__(self: _ArrayND[timedelta64], other: _ArrayLikeFloat_co) -> _ArrayND[timedelta64]: ...
@overload
def __imul__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __imul__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __itruediv__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __itruediv__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
@overload
def __itruediv__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
@overload
def __itruediv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
def __itruediv__(self: _ArrayND[timedelta64], other: _ArrayLikeInt_co) -> _ArrayND[timedelta64]: ...
@overload
def __itruediv__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __itruediv__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __ifloordiv__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __ifloordiv__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __ifloordiv__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __ifloordiv__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
@overload
def __ifloordiv__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
@overload
def __ifloordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeBool_co) -> NoReturn: ...
@overload
def __ifloordiv__(self: _ArrayND[timedelta64], other: _ArrayLikeInt_co) -> _ArrayND[timedelta64]: ...
@overload
def __ifloordiv__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __ifloordiv__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __ipow__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __ipow__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __ipow__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __ipow__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
@overload
def __ipow__(self: _ArrayND[complexfloating[_NBit1, _NBit1]], other: _ArrayLikeComplex_co) -> _ArrayND[complexfloating[_NBit1, _NBit1]]: ...
@overload
def __ipow__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __ipow__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __imod__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __imod__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __imod__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __imod__(self: _ArrayND[floating[_NBit1]], other: _ArrayLikeFloat_co) -> _ArrayND[floating[_NBit1]]: ...
@overload
def __imod__(self: _ArrayND[timedelta64], other: _NestedSequence[_SupportsArray[dtype[timedelta64]]]) -> _ArrayND[timedelta64]: ...
@overload
def __imod__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __imod__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __ilshift__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __ilshift__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __ilshift__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __ilshift__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __ilshift__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __irshift__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __irshift__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __irshift__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __irshift__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __irshift__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __iand__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __iand__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
@overload
def __iand__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __iand__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __iand__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __iand__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __ixor__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __ixor__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
@overload
def __ixor__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __ixor__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __ixor__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __ixor__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

@overload # type: ignore[misc]
def __ior__(self: _ArrayND[Any], other: _NestedSequence[str | bytes]) -> NoReturn: ...
@overload
def __ior__(self: _ArrayND[bool_], other: _ArrayLikeBool_co) -> _ArrayND[bool_]: ...
@overload
def __ior__(self: _ArrayND[unsignedinteger[_NBit1]], other: _ArrayLikeUInt_co) -> _ArrayND[unsignedinteger[_NBit1]]: ...
@overload
def __ior__(self: _ArrayND[signedinteger[_NBit1]], other: _ArrayLikeInt_co) -> _ArrayND[signedinteger[_NBit1]]: ...
@overload
def __ior__(self: _ArrayND[object_], other: Any) -> _ArrayND[object_]: ...
@overload
def __ior__(self: _ArrayND[_ScalarType], other: _RecursiveSequence) -> _ArrayND[_ScalarType]: ...

# Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
@property
Expand Down
0