Skip to content

Commit c6d4966

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

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
@@ -169,6 +169,27 @@ def __isub__(self, other: Self | int | float, /) -> Self:
169169
...
170170

171171

172+
class CanArrayRSub(Protocol):
173+
"""Protocol for array classes that support the right subtraction operator."""
174+
175+
def __rsub__(self, other: Self | int | float, /) -> Self:
176+
"""Calculates the difference for each element of the array `other` with the respective element of an array instance.
177+
178+
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`).
179+
180+
Args:
181+
other: minuend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
182+
183+
Returns:
184+
Self: an array containing the element-wise differences. The returned array must have a data type determined by Type Promotion Rules.
185+
186+
See Also:
187+
array_api_typing.Subtract
188+
189+
""" # noqa: E501
190+
...
191+
192+
172193
class CanArrayMul(Protocol):
173194
"""Protocol for array classes that support the multiplication operator."""
174195

@@ -366,6 +387,7 @@ class Array(
366387
CanArrayRAdd,
367388
CanArraySub,
368389
CanArrayISub,
390+
CanArrayRSub,
369391
CanArrayMul,
370392
CanArrayIMul,
371393
CanArrayTrueDiv,

0 commit comments

Comments
 (0)