Skip to content

Commit 2696f0a

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

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

174174

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

@@ -254,6 +273,7 @@ class Array(
254273
CanArraySub,
255274
CanArrayISub,
256275
CanArrayMul,
276+
CanArrayIMul,
257277
CanArrayTrueDiv,
258278
CanArrayFloorDiv,
259279
CanArrayMod,

0 commit comments

Comments
 (0)