Skip to content

Commit 6cc70ac

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

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ 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: `self`, after performing the in-place addition. The returned array must have a data type determined by Type Promotion Rules.
101+
102+
See Also:
103+
array_api_typing.Add
104+
105+
""" # noqa: E501
106+
...
107+
108+
90109
class CanArraySub(Protocol):
91110
"""Protocol for array classes that support the subtraction operator."""
92111

@@ -210,6 +229,7 @@ class Array(
210229
CanArrayPos,
211230
CanArrayNeg,
212231
CanArrayAdd,
232+
CanArrayIAdd,
213233
CanArraySub,
214234
CanArrayMul,
215235
CanArrayTrueDiv,

0 commit comments

Comments
 (0)