Skip to content

Commit 66c50b8

Browse files
committed
✨: add CanArrayMod protocol
Support modulo operator for array classes
1 parent 5b873c7 commit 66c50b8

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
@@ -172,6 +172,25 @@ def __floordiv__(self, other: Self | int | float, /) -> Self:
172172
...
173173

174174

175+
class CanArrayMod(Protocol):
176+
"""Protocol for array classes that support the modulo operator."""
177+
178+
def __mod__(self, other: Self | int | float, /) -> Self:
179+
"""Evaluates `self_i % other_i` for each element of an array instance with the respective element of the array `other`.
180+
181+
Args:
182+
other: Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
183+
184+
Returns:
185+
Self: an array containing the element-wise results. Each element-wise result must have the same sign as the respective element `other_i`. The returned array must have a floating-point data type determined by Type Promotion Rules.
186+
187+
See Also:
188+
array_api_typing.Remainder
189+
190+
""" # noqa: E501
191+
...
192+
193+
175194
class Array(
176195
HasArrayNamespace[NS_co],
177196
CanArrayPos,
@@ -181,6 +200,7 @@ class Array(
181200
CanArrayMul,
182201
CanArrayTrueDiv,
183202
CanArrayFloorDiv,
203+
CanArrayMod,
184204
Protocol,
185205
):
186206
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)