Skip to content

Commit e19b28a

Browse files
committed
✨: add CanArrayRSub protocol
Support right subtraction operator for array classes
1 parent fe86cd6 commit e19b28a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ def __isub__(self, other: Self | int | float, /) -> Self:
171171
...
172172

173173

174+
class CanArrayRSub(Protocol):
175+
"""Protocol for array classes that support the right subtraction operator."""
176+
177+
def __rsub__(self, other: Self | int | float, /) -> Self:
178+
"""Calculates the difference for each element of the array `other` with the respective element of an array instance.
179+
180+
The result of `other_i - self_i` must be the same as `other_i + (-self_i)` and must be governed by the same floating-point rules as addition (see `CanArrayAdd`).
181+
182+
Args:
183+
other: minuend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
184+
185+
Returns:
186+
Self: an array containing the element-wise differences. The returned array must have a data type determined by Type Promotion Rules.
187+
188+
See Also:
189+
array_api_typing.Subtract
190+
191+
""" # noqa: E501
192+
...
193+
194+
174195
class CanArrayMul(Protocol):
175196
"""Protocol for array classes that support the multiplication operator."""
176197

@@ -368,6 +389,7 @@ class Array(
368389
CanArrayRAdd,
369390
CanArraySub,
370391
CanArrayISub,
392+
CanArrayRSub,
371393
CanArrayMul,
372394
CanArrayIMul,
373395
CanArrayTrueDiv,

0 commit comments

Comments
 (0)