Skip to content

Commit d69611a

Browse files
committed
✨: add HasArrayMod protocol to support modulo operator for array classes
1 parent f98896e commit d69611a

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
@@ -142,6 +142,22 @@ def __floordiv__(self, other: Self | int | float, /) -> Self:
142142
...
143143

144144

145+
class HasArrayMod(Protocol):
146+
"""Protocol for array classes that support the modulo operator."""
147+
148+
def __mod__(self, other: Self | int | float, /) -> Self:
149+
"""Calculates the remainder for each element of an array instance with the respective element of the array other.
150+
151+
Args:
152+
other: divisor array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
153+
154+
Returns:
155+
an array containing the element-wise remainders. The returned array must have a data type determined by Type Promotion Rules.
156+
157+
""" # noqa: E501
158+
...
159+
160+
145161
class Array(
146162
HasArrayNamespace[NS_co],
147163
HasArrayPos,
@@ -151,6 +167,7 @@ class Array(
151167
HasArrayMul,
152168
HasArrayTrueDiv,
153169
HasArrayFloorDiv,
170+
HasArrayMod,
154171
Protocol,
155172
):
156173
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)