Skip to content

Commit 5ce8592

Browse files
committed
✨: add CanArrayPow protocol
Support power operator for array classes
1 parent 66c50b8 commit 5ce8592

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

193193

194+
class CanArrayPow(Protocol):
195+
"""Protocol for array classes that support the power operator."""
196+
197+
def __pow__(self, other: Self | int | float, /) -> Self:
198+
"""Calculates an implementation-dependent approximation of exponentiation by raising each element (the base) of an array instance to the power of `other_i` (the exponent), where `other_i` is the corresponding element of the array `other`.
199+
200+
Args:
201+
other: array whose elements correspond to the exponentiation exponent. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
202+
203+
Returns:
204+
Self: an array containing the element-wise results. The returned array must have a data type determined by Type Promotion Rules.
205+
206+
""" # noqa: E501
207+
...
208+
209+
194210
class Array(
195211
HasArrayNamespace[NS_co],
196212
CanArrayPos,
@@ -201,6 +217,7 @@ class Array(
201217
CanArrayTrueDiv,
202218
CanArrayFloorDiv,
203219
CanArrayMod,
220+
CanArrayPow,
204221
Protocol,
205222
):
206223
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)