Skip to content

Commit 6bb01a8

Browse files
committed
✨: add CanArrayRPow protocol
Support right power operator for array classes
1 parent fa4e6b8 commit 6bb01a8

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
@@ -437,6 +437,25 @@ def __ipow__(self, other: Self | int | float, /) -> Self:
437437
...
438438

439439

440+
class CanArrayRPow(Protocol):
441+
"""Protocol for array classes that support the right power operator."""
442+
443+
def __rpow__(self, other: Self | int | float, /) -> Self:
444+
"""Calculates the power for each element of the array `other` raised to the respective element of an array instance.
445+
446+
Args:
447+
other: base array. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
448+
449+
Returns:
450+
Self: an array containing the element-wise powers. The returned array must have a data type determined by Type Promotion Rules.
451+
452+
See Also:
453+
array_api_typing.Power
454+
455+
""" # noqa: E501
456+
...
457+
458+
440459
class Array(
441460
HasArrayNamespace[NS_co],
442461
CanArrayPos,
@@ -459,6 +478,7 @@ class Array(
459478
CanArrayIMod,
460479
CanArrayPow,
461480
CanArrayIPow,
481+
CanArrayRPow,
462482
Protocol,
463483
):
464484
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)