Skip to content

Commit 25d0170

Browse files
committed
✨: add CanArrayIAdd protocol
Support in-place addition operator for array classes
1 parent 5ce8592 commit 25d0170

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
@@ -89,6 +89,25 @@ def __add__(self, other: Self | int | float, /) -> Self:
8989
...
9090

9191

92+
class CanArrayIAdd(Protocol):
93+
"""Protocol for array classes that support the in-place addition operator."""
94+
95+
def __iadd__(self, other: Self | int | float, /) -> Self:
96+
"""Calculates the in-place sum for each element of an array instance with the respective element of the array `other`.
97+
98+
Args:
99+
other: addend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
100+
101+
Returns:
102+
Self: `self`, after performing the in-place addition. The returned array must have a data type determined by Type Promotion Rules.
103+
104+
See Also:
105+
array_api_typing.Add
106+
107+
""" # noqa: E501
108+
...
109+
110+
92111
class CanArraySub(Protocol):
93112
"""Protocol for array classes that support the subtraction operator."""
94113

@@ -212,6 +231,7 @@ class Array(
212231
CanArrayPos,
213232
CanArrayNeg,
214233
CanArrayAdd,
234+
CanArrayIAdd,
215235
CanArraySub,
216236
CanArrayMul,
217237
CanArrayTrueDiv,

0 commit comments

Comments
 (0)