Skip to content

Commit b7e216d

Browse files
committed
✨: add CanArrayISub protocol
Support in-place subtraction operator for array classes
1 parent 6cc70ac commit b7e216d

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
@@ -131,6 +131,25 @@ def __sub__(self, other: Self | int | float, /) -> Self:
131131
...
132132

133133

134+
class CanArrayISub(Protocol):
135+
"""Protocol for array classes that support the in-place subtraction operator."""
136+
137+
def __isub__(self, other: Self | int | float, /) -> Self:
138+
"""Calculates the in-place difference for each element of an array instance with the respective element of the array `other`.
139+
140+
Args:
141+
other: subtrahend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
142+
143+
Returns:
144+
Self: `self`, after performing the in-place subtraction. The returned array must have a data type determined by Type Promotion Rules.
145+
146+
See Also:
147+
array_api_typing.Subtract
148+
149+
""" # noqa: E501
150+
...
151+
152+
134153
class CanArrayMul(Protocol):
135154
"""Protocol for array classes that support the multiplication operator."""
136155

@@ -231,6 +250,7 @@ class Array(
231250
CanArrayAdd,
232251
CanArrayIAdd,
233252
CanArraySub,
253+
CanArrayISub,
234254
CanArrayMul,
235255
CanArrayTrueDiv,
236256
CanArrayFloorDiv,

0 commit comments

Comments
 (0)