Skip to content

Commit 953458a

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

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
@@ -114,12 +114,33 @@ def __sub__(self, other: Self | int | float, /) -> Self:
114114
...
115115

116116

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

0 commit comments

Comments
 (0)