Skip to content

Commit 546178f

Browse files
committed
✨: add HasArrayMul protocol to support multiplication operator for array classes
1 parent 97278f5 commit 546178f

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
@@ -94,12 +94,29 @@ def __sub__(self, other: Self | int | float, /) -> Self:
9494
...
9595

9696

97+
class HasArrayMul(Protocol):
98+
"""Protocol for array classes that support the multiplication operator."""
99+
100+
def __mul__(self, other: Self | int | float, /) -> Self:
101+
"""Calculates the product for each element of an array instance with the respective element of the array other.
102+
103+
Args:
104+
other: multiplicand array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
105+
106+
Returns:
107+
an array containing the element-wise products. The returned array must have a data type determined by Type Promotion Rules.
108+
109+
""" # noqa: E501
110+
...
111+
112+
97113
class Array(
98114
HasArrayNamespace[NS_co],
99115
HasArrayPos,
100116
HasArrayNeg,
101117
HasArrayAdd,
102118
HasArraySub,
119+
HasArrayMul,
103120
Protocol,
104121
):
105122
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)