Skip to content

Commit b232bd9

Browse files
committed
✨: add CanArrayIMul protocol
Support in-place multiplication operator for array classes
1 parent b7e216d commit b232bd9

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
@@ -170,6 +170,25 @@ def __mul__(self, other: Self | int | float, /) -> Self:
170170
...
171171

172172

173+
class CanArrayIMul(Protocol):
174+
"""Protocol for array classes that support the in-place multiplication operator."""
175+
176+
def __imul__(self, other: Self | int | float, /) -> Self:
177+
"""Calculates the in-place product for each element of an array instance with the respective element of the array `other`.
178+
179+
Args:
180+
other: multiplicand array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
181+
182+
Returns:
183+
Self: `self`, after performing the in-place multiplication. The returned array must have a data type determined by Type Promotion Rules.
184+
185+
See Also:
186+
array_api_typing.Multiply
187+
188+
""" # noqa: E501
189+
...
190+
191+
173192
class CanArrayTrueDiv(Protocol):
174193
"""Protocol for array classes that support the true division operator."""
175194

@@ -252,6 +271,7 @@ class Array(
252271
CanArraySub,
253272
CanArrayISub,
254273
CanArrayMul,
274+
CanArrayIMul,
255275
CanArrayTrueDiv,
256276
CanArrayFloorDiv,
257277
CanArrayMod,

0 commit comments

Comments
 (0)