Skip to content

Commit 111e3b5

Browse files
committed
✨: add CanArrayIPow protocol
Support in-place power operator for array classes
1 parent 78194dc commit 111e3b5

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
@@ -300,6 +300,25 @@ def __pow__(self, other: Self | int | float, /) -> Self:
300300
...
301301

302302

303+
class CanArrayIPow(Protocol):
304+
"""Protocol for array classes that support the in-place power operator."""
305+
306+
def __ipow__(self, other: Self | int | float, /) -> Self:
307+
"""Calculates the in-place power for each element of an array instance with the respective element of the array `other`.
308+
309+
Args:
310+
other: exponent array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
311+
312+
Returns:
313+
Self: `self`, after performing the in-place power operation. The returned array must have a data type determined by Type Promotion Rules.
314+
315+
See Also:
316+
array_api_typing.Power
317+
318+
""" # noqa: E501
319+
...
320+
321+
303322
class Array(
304323
HasArrayNamespace[NS_co],
305324
CanArrayPos,
@@ -315,6 +334,7 @@ class Array(
315334
CanArrayIFloorDiv,
316335
CanArrayMod,
317336
CanArrayPow,
337+
CanArrayIPow,
318338
Protocol,
319339
):
320340
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)