Skip to content

Commit bbcf341

Browse files
committed
✨: add CanArrayRMul protocol
Support right multiplication operator for array classes
1 parent c6d4966 commit bbcf341

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

231231

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

@@ -390,6 +409,7 @@ class Array(
390409
CanArrayRSub,
391410
CanArrayMul,
392411
CanArrayIMul,
412+
CanArrayRMul,
393413
CanArrayTrueDiv,
394414
CanArrayFloorDiv,
395415
CanArrayIFloorDiv,

0 commit comments

Comments
 (0)