Skip to content

Commit fe86cd6

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

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

110110

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

@@ -346,6 +365,7 @@ class Array(
346365
CanArrayNeg,
347366
CanArrayAdd,
348367
CanArrayIAdd,
368+
CanArrayRAdd,
349369
CanArraySub,
350370
CanArrayISub,
351371
CanArrayMul,

0 commit comments

Comments
 (0)