Skip to content

Commit 0518856

Browse files
committed
✨: add CanArrayMod protocol
Support modulo operator for array classes
1 parent b4acd32 commit 0518856

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

172172

173+
class CanArrayMod(Protocol):
174+
"""Protocol for array classes that support the modulo operator."""
175+
176+
def __mod__(self, other: Self | int | float, /) -> Self:
177+
"""Evaluates `self_i % other_i` for each element of an array instance with the respective element of the array `other`.
178+
179+
Args:
180+
other: Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
181+
182+
Returns:
183+
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.
184+
185+
See Also:
186+
array_api_typing.Remainder
187+
188+
""" # noqa: E501
189+
...
190+
191+
173192
class Array(
174193
HasArrayNamespace[NS_co],
175194
CanArrayPos,
@@ -179,6 +198,7 @@ class Array(
179198
CanArrayMul,
180199
CanArrayTrueDiv,
181200
CanArrayFloorDiv,
201+
CanArrayMod,
182202
Protocol,
183203
):
184204
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)