Skip to content

Commit 98f864f

Browse files
committed
✨: add CanArrayRAdd protocol
Support right addition operator for array classes Signed-off-by: Nathaniel Starkman <nstarman@users.noreply.github.com>
1 parent d313c34 commit 98f864f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ def __iadd__(self, other: Self | int | float, /) -> Self:
103103
...
104104

105105

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

@@ -325,6 +341,7 @@ class Array(
325341
CanArrayNeg,
326342
CanArrayAdd,
327343
CanArrayIAdd,
344+
CanArrayRAdd,
328345
CanArraySub,
329346
CanArrayISub,
330347
CanArrayMul,

0 commit comments

Comments
 (0)