Skip to content

Commit 27f625c

Browse files
committed
✨: add HasArrayPow protocol to support power operator for array classes
1 parent d69611a commit 27f625c

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
@@ -158,6 +158,22 @@ def __mod__(self, other: Self | int | float, /) -> Self:
158158
...
159159

160160

161+
class HasArrayPow(Protocol):
162+
"""Protocol for array classes that support the power operator."""
163+
164+
def __pow__(self, other: Self | int | float, /) -> Self:
165+
"""Calculates the power for each element of an array instance with the respective element of the array other.
166+
167+
Args:
168+
other: exponent array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
169+
170+
Returns:
171+
an array containing the element-wise powers. The returned array must have a data type determined by Type Promotion Rules.
172+
173+
""" # noqa: E501
174+
...
175+
176+
161177
class Array(
162178
HasArrayNamespace[NS_co],
163179
HasArrayPos,
@@ -168,6 +184,7 @@ class Array(
168184
HasArrayTrueDiv,
169185
HasArrayFloorDiv,
170186
HasArrayMod,
187+
HasArrayPow,
171188
Protocol,
172189
):
173190
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)