Skip to content

Commit 65c9191

Browse files
committed
✨: add HasArrayRPow protocol
Support right power operator for array classes
1 parent 08eb4e1 commit 65c9191

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
@@ -401,6 +401,22 @@ def __ipow__(self, other: Self | int | float, /) -> Self:
401401
...
402402

403403

404+
class CanArrayRPow(Protocol):
405+
"""Protocol for array classes that support the right power operator."""
406+
407+
def __rpow__(self, other: Self | int | float, /) -> Self:
408+
"""Calculates the power for each element of an array instance with the respective element of the array other.
409+
410+
Args:
411+
other: exponent array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
412+
413+
Returns:
414+
an array containing the element-wise powers. The returned array must have a data type determined by Type Promotion Rules.
415+
416+
""" # noqa: E501
417+
...
418+
419+
404420
class Array(
405421
HasArrayNamespace[NS_co],
406422
CanArrayPos,
@@ -423,6 +439,7 @@ class Array(
423439
CanArrayIMod,
424440
CanArrayPow,
425441
CanArrayIPow,
442+
CanArrayRPow,
426443
Protocol,
427444
):
428445
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)