Skip to content

Commit 5b873c7

Browse files
committed
✨: add CanArrayFloorDiv protocol
Support floor division operator for array classes
1 parent ea598bc commit 5b873c7

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
@@ -153,6 +153,25 @@ def __truediv__(self, other: Self | int | float, /) -> Self:
153153
...
154154

155155

156+
class CanArrayFloorDiv(Protocol):
157+
"""Protocol for array classes that support the floor division operator."""
158+
159+
def __floordiv__(self, other: Self | int | float, /) -> Self:
160+
"""Evaluates `self_i // other_i` for each element of an array instance with the respective element of the array `other`.
161+
162+
Args:
163+
other: Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
164+
165+
Returns:
166+
Self: an array containing the element-wise results. The returned array must have a data type determined by Type Promotion Rules.
167+
168+
See Also:
169+
array_api_typing.FloorDiv
170+
171+
""" # noqa: E501
172+
...
173+
174+
156175
class Array(
157176
HasArrayNamespace[NS_co],
158177
CanArrayPos,
@@ -161,6 +180,7 @@ class Array(
161180
CanArraySub,
162181
CanArrayMul,
163182
CanArrayTrueDiv,
183+
CanArrayFloorDiv,
164184
Protocol,
165185
):
166186
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)