Skip to content

Commit 3e4bce4

Browse files
committed
✨: add CanArrayISub protocol
Support in-place subtraction operator for array classes
1 parent 18fac19 commit 3e4bce4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ def __sub__(self, other: Self | int | float, /) -> Self:
128128
...
129129

130130

131+
class CanArrayISub(Protocol):
132+
"""Protocol for array classes that support the in-place subtraction operator."""
133+
134+
def __isub__(self, other: Self | int | float, /) -> Self:
135+
"""Calculates the in-place difference for each element of an array instance with the respective element of the array other.
136+
137+
The result of self_i - other_i must be the same as self_i + (-other_i) and must be governed by the same floating-point rules as addition (see array.__add__()).
138+
139+
Args:
140+
other: subtrahend array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
141+
142+
Returns:
143+
self, after performing the in-place subtraction.
144+
145+
""" # noqa: E501
146+
...
147+
148+
131149
class CanArrayMul(Protocol):
132150
"""Protocol for array classes that support the multiplication operator."""
133151

@@ -228,6 +246,7 @@ class Array(
228246
CanArrayAdd,
229247
CanArrayIAdd,
230248
CanArraySub,
249+
CanArrayISub,
231250
CanArrayMul,
232251
CanArrayTrueDiv,
233252
CanArrayFloorDiv,

0 commit comments

Comments
 (0)