Skip to content

Commit a9c9587

Browse files
committed
✨: add CanArrayRSub protocol
Support right subtraction operator for array classes
1 parent 98f864f commit a9c9587

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
@@ -162,6 +162,24 @@ def __isub__(self, other: Self | int | float, /) -> Self:
162162
...
163163

164164

165+
class CanArrayRSub(Protocol):
166+
"""Protocol for array classes that support the right subtraction operator."""
167+
168+
def __rsub__(self, other: Self | int | float, /) -> Self:
169+
"""Calculates the difference for each element of an array instance with the respective element of the array other.
170+
171+
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__()).
172+
173+
Args:
174+
other: subtrahend array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
175+
176+
Returns:
177+
an array containing the element-wise differences. The returned array must have a data type determined by Type Promotion Rules.
178+
179+
""" # noqa: E501
180+
...
181+
182+
165183
class CanArrayMul(Protocol):
166184
"""Protocol for array classes that support the multiplication operator."""
167185

@@ -344,6 +362,7 @@ class Array(
344362
CanArrayRAdd,
345363
CanArraySub,
346364
CanArrayISub,
365+
CanArrayRSub,
347366
CanArrayMul,
348367
CanArrayIMul,
349368
CanArrayTrueDiv,

0 commit comments

Comments
 (0)