Skip to content

Commit ea598bc

Browse files
committed
✨: add CanArrayTrueDiv protocol
Support true division operator for array classes
1 parent 953458a commit ea598bc

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
@@ -134,13 +134,33 @@ def __mul__(self, other: Self | int | float, /) -> Self:
134134
...
135135

136136

137+
class CanArrayTrueDiv(Protocol):
138+
"""Protocol for array classes that support the true division operator."""
139+
140+
def __truediv__(self, other: Self | int | float, /) -> Self:
141+
"""Evaluates `self_i / other_i` for each element of an array instance with the respective element of the array `other`.
142+
143+
Args:
144+
other: Must be compatible with `self` (see Broadcasting). Should have a numeric data type.
145+
146+
Returns:
147+
Self: an array containing the element-wise results. The returned array should have a floating-point data type determined by Type Promotion Rules.
148+
149+
See Also:
150+
array_api_typing.TrueDiv
151+
152+
""" # noqa: E501
153+
...
154+
155+
137156
class Array(
138157
HasArrayNamespace[NS_co],
139158
CanArrayPos,
140159
CanArrayNeg,
141160
CanArrayAdd,
142161
CanArraySub,
143162
CanArrayMul,
163+
CanArrayTrueDiv,
144164
Protocol,
145165
):
146166
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)