Skip to content

Commit 18fac19

Browse files
committed
✨: add CanArrayIAdd protocol
Support in-place addition operator for array classes
1 parent f47d4af commit 18fac19

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,22 @@ def __add__(self, other: Self | int | float, /) -> Self:
8787
...
8888

8989

90+
class CanArrayIAdd(Protocol):
91+
"""Protocol for array classes that support the in-place addition operator."""
92+
93+
def __iadd__(self, other: Self | int | float, /) -> Self:
94+
"""Calculates the in-place sum for each element of an array instance with the respective element of the array other.
95+
96+
Args:
97+
other: addend array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
98+
99+
Returns:
100+
self, after performing the in-place addition.
101+
102+
""" # noqa: E501
103+
...
104+
105+
90106
class CanArraySub(Protocol):
91107
"""Protocol for array classes that support the subtraction operator."""
92108

@@ -210,6 +226,7 @@ class Array(
210226
CanArrayPos,
211227
CanArrayNeg,
212228
CanArrayAdd,
229+
CanArrayIAdd,
213230
CanArraySub,
214231
CanArrayMul,
215232
CanArrayTrueDiv,

0 commit comments

Comments
 (0)