Skip to content

Commit e2e3333

Browse files
committed
✨: add CanArrayTrueDiv protocol
Support true division operator for array classes
1 parent da34fcb commit e2e3333

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

134134

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

0 commit comments

Comments
 (0)