Skip to content

Commit 70e790d

Browse files
committed
✨: add HasArrayRMul protocol
Support right multiplication operator for array classes
1 parent 0c021e9 commit 70e790d

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
@@ -194,6 +194,22 @@ def __imul__(self, other: Self | int | float, /) -> Self:
194194
...
195195

196196

197+
class CanArrayRMul(Protocol):
198+
"""Protocol for array classes that support the right multiplication operator."""
199+
200+
def __rmul__(self, other: Self | int | float, /) -> Self:
201+
"""Calculates the product for each element of an array instance with the respective element of the array other.
202+
203+
Args:
204+
other: multiplicand array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
205+
206+
Returns:
207+
an array containing the element-wise products. The returned array must have a data type determined by Type Promotion Rules.
208+
209+
""" # noqa: E501
210+
...
211+
212+
197213
class CanArrayTrueDiv(Protocol):
198214
"""Protocol for array classes that support the true division operator."""
199215

@@ -334,6 +350,7 @@ class Array(
334350
CanArrayRSub,
335351
CanArrayMul,
336352
CanArrayIMul,
353+
CanArrayRMul,
337354
CanArrayTrueDiv,
338355
CanArrayFloorDiv,
339356
CanArrayIFloorDiv,

0 commit comments

Comments
 (0)