Skip to content

Commit da34fcb

Browse files
committed
✨: add HasArrayMul protocol
Support multiplication operator for array classes Signed-off-by: Nathaniel Starkman <[email protected]>
1 parent f72ba68 commit da34fcb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,33 @@ def __sub__(self, other: Self | int | float, /) -> Self:
112112
...
113113

114114

115+
class CanArrayMul(Protocol):
116+
"""Protocol for array classes that support the multiplication operator."""
117+
118+
def __mul__(self, other: Self | int | float, /) -> Self:
119+
"""Calculates the product for each element of an array instance with the respective element of the array `other`.
120+
121+
Args:
122+
other: multiplicand array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
123+
124+
Returns:
125+
Self: an array containing the element-wise products. The returned
126+
array must have a data type determined by Type Promotion Rules.
127+
128+
See Also:
129+
array_api_typing.Multiply
130+
131+
""" # noqa: E501
132+
...
133+
134+
115135
class Array(
116136
HasArrayNamespace[NS_co],
117137
CanArrayPos,
118138
CanArrayNeg,
119139
CanArrayAdd,
120140
CanArraySub,
141+
CanArrayMul,
121142
Protocol,
122143
):
123144
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)