Skip to content

Commit c0ec500

Browse files
committed
✨: add CanArrayRPow protocol
Support right power operator for array classes
1 parent 94b8d8a commit c0ec500

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

437437

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

0 commit comments

Comments
 (0)