Skip to content

Commit 5e07c4a

Browse files
committed
✨: add CanArrayIMul protocol
Support in-place multiplication operator for array classes
1 parent 3e4bce4 commit 5e07c4a

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
@@ -166,6 +166,22 @@ def __mul__(self, other: Self | int | float, /) -> Self:
166166
...
167167

168168

169+
class CanArrayIMul(Protocol):
170+
"""Protocol for array classes that support the in-place multiplication operator."""
171+
172+
def __imul__(self, other: Self | int | float, /) -> Self:
173+
"""Calculates the in-place product for each element of an array instance with the respective element of the array other.
174+
175+
Args:
176+
other: multiplicand array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
177+
178+
Returns:
179+
Self: after performing the in-place multiplication.
180+
181+
""" # noqa: E501
182+
...
183+
184+
169185
class CanArrayTrueDiv(Protocol):
170186
"""Protocol for array classes that support the true division operator."""
171187

@@ -248,6 +264,7 @@ class Array(
248264
CanArraySub,
249265
CanArrayISub,
250266
CanArrayMul,
267+
CanArrayIMul,
251268
CanArrayTrueDiv,
252269
CanArrayFloorDiv,
253270
CanArrayMod,

0 commit comments

Comments
 (0)