Skip to content

Commit f47d4af

Browse files
committed
✨: add CanArrayPow protocol
Support power operator for array classes
1 parent 0518856 commit f47d4af

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

191191

192+
class CanArrayPow(Protocol):
193+
"""Protocol for array classes that support the power operator."""
194+
195+
def __pow__(self, other: Self | int | float, /) -> Self:
196+
"""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`.
197+
198+
Args:
199+
other: array whose elements correspond to the exponentiation exponent. Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
200+
201+
Returns:
202+
Self: an array containing the element-wise results. The returned array must have a data type determined by Type Promotion Rules.
203+
204+
""" # noqa: E501
205+
...
206+
207+
192208
class Array(
193209
HasArrayNamespace[NS_co],
194210
CanArrayPos,
@@ -199,6 +215,7 @@ class Array(
199215
CanArrayTrueDiv,
200216
CanArrayFloorDiv,
201217
CanArrayMod,
218+
CanArrayPow,
202219
Protocol,
203220
):
204221
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)