Skip to content

Commit b6ea877

Browse files
committed
✨: add HasArrayRPow protocol
Support right power operator for array classes
1 parent 7f9cf89 commit b6ea877

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

372372

373+
class CanArrayRPow(Protocol):
374+
"""Protocol for array classes that support the right power operator."""
375+
376+
def __rpow__(self, other: Self | int | float, /) -> Self:
377+
"""Calculates the power for each element of an array instance with the respective element of the array other.
378+
379+
Args:
380+
other: exponent array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
381+
382+
Returns:
383+
an array containing the element-wise powers. The returned array must have a data type determined by Type Promotion Rules.
384+
385+
""" # noqa: E501
386+
...
387+
388+
373389
class Array(
374390
HasArrayNamespace[NS_co],
375391
CanArrayPos,
@@ -392,6 +408,7 @@ class Array(
392408
CanArrayIMod,
393409
CanArrayPow,
394410
CanArrayIPow,
411+
CanArrayRPow,
395412
Protocol,
396413
):
397414
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)