Skip to content

Commit 14b282a

Browse files
committed
✨: add CanArrayRMul protocol
Support right multiplication operator for array classes
1 parent a9c9587 commit 14b282a

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

218218

219+
class CanArrayRMul(Protocol):
220+
"""Protocol for array classes that support the right multiplication operator."""
221+
222+
def __rmul__(self, other: Self | int | float, /) -> Self:
223+
"""Calculates the product for each element of an array instance with the respective element of the array other.
224+
225+
Args:
226+
other: multiplicand array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
227+
228+
Returns:
229+
an array containing the element-wise products. The returned array must have a data type determined by Type Promotion Rules.
230+
231+
""" # noqa: E501
232+
...
233+
234+
219235
class CanArrayTrueDiv(Protocol):
220236
"""Protocol for array classes that support the true division operator."""
221237

@@ -365,6 +381,7 @@ class Array(
365381
CanArrayRSub,
366382
CanArrayMul,
367383
CanArrayIMul,
384+
CanArrayRMul,
368385
CanArrayTrueDiv,
369386
CanArrayFloorDiv,
370387
CanArrayIFloorDiv,

0 commit comments

Comments
 (0)