Skip to content

Commit bee031f

Browse files
committed
✨: add CanArrayISub protocol
Support in-place subtraction operator for array classes
1 parent 25d0170 commit bee031f

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

135135

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

@@ -233,6 +252,7 @@ class Array(
233252
CanArrayAdd,
234253
CanArrayIAdd,
235254
CanArraySub,
255+
CanArrayISub,
236256
CanArrayMul,
237257
CanArrayTrueDiv,
238258
CanArrayFloorDiv,

0 commit comments

Comments
 (0)