Skip to content

Commit aac59ea

Browse files
committed
✨: add CanArrayRAdd protocol
Support right addition operator for array classes Signed-off-by: Nathaniel Starkman <[email protected]>
1 parent b1bfa16 commit aac59ea

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
@@ -106,6 +106,25 @@ def __iadd__(self, other: Self | int | float, /) -> Self:
106106
...
107107

108108

109+
class CanArrayRAdd(Protocol):
110+
"""Protocol for array classes that support the right addition operator."""
111+
112+
def __radd__(self, other: Self | int | float, /) -> Self:
113+
"""Calculates the sum for each element of the array `other` with the respective element of an array instance.
114+
115+
Args:
116+
other: addend array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
117+
118+
Returns:
119+
Self: an array containing the element-wise sums. The returned array must have a data type determined by Type Promotion Rules.
120+
121+
See Also:
122+
array_api_typing.Add
123+
124+
""" # noqa: E501
125+
...
126+
127+
109128
class CanArraySub(Protocol):
110129
"""Protocol for array classes that support the subtraction operator."""
111130

@@ -344,6 +363,7 @@ class Array(
344363
CanArrayNeg,
345364
CanArrayAdd,
346365
CanArrayIAdd,
366+
CanArrayRAdd,
347367
CanArraySub,
348368
CanArrayISub,
349369
CanArrayMul,

0 commit comments

Comments
 (0)