Skip to content

Commit 5165e18

Browse files
committed
✨: add CanArrayRMul protocol
Support right multiplication operator for array classes
1 parent e19b28a commit 5165e18

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
@@ -231,6 +231,25 @@ def __imul__(self, other: Self | int | float, /) -> Self:
231231
...
232232

233233

234+
class CanArrayRMul(Protocol):
235+
"""Protocol for array classes that support the right multiplication operator."""
236+
237+
def __rmul__(self, other: Self | int | float, /) -> Self:
238+
"""Calculates the product for each element of the array `other` with the respective element of an array instance.
239+
240+
Args:
241+
other: multiplicand array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
242+
243+
Returns:
244+
Self: an array containing the element-wise products. The returned array must have a data type determined by Type Promotion Rules.
245+
246+
See Also:
247+
array_api_typing.Multiply
248+
249+
""" # noqa: E501
250+
...
251+
252+
234253
class CanArrayTrueDiv(Protocol):
235254
"""Protocol for array classes that support the true division operator."""
236255

@@ -392,6 +411,7 @@ class Array(
392411
CanArrayRSub,
393412
CanArrayMul,
394413
CanArrayIMul,
414+
CanArrayRMul,
395415
CanArrayTrueDiv,
396416
CanArrayFloorDiv,
397417
CanArrayIFloorDiv,

0 commit comments

Comments
 (0)