Skip to content

Commit 439c70a

Browse files
committed
✨: add HasArrayTrueDiv protocol to support true division operator for array classes
1 parent 546178f commit 439c70a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,30 @@ def __mul__(self, other: Self | int | float, /) -> Self:
110110
...
111111

112112

113+
class HasArrayTrueDiv(Protocol):
114+
"""Protocol for array classes that support the true division operator."""
115+
116+
def __truediv__(self, other: Self | int | float, /) -> Self:
117+
"""Calculates the quotient for each element of an array instance with the respective element of the array other.
118+
119+
Args:
120+
other: divisor array. Must be compatible with self (see Broadcasting). Should have a numeric data type.
121+
122+
Returns:
123+
an array containing the element-wise quotients. The returned array must have a data type determined by Type Promotion Rules.
124+
125+
""" # noqa: E501
126+
...
127+
128+
113129
class Array(
114130
HasArrayNamespace[NS_co],
115131
HasArrayPos,
116132
HasArrayNeg,
117133
HasArrayAdd,
118134
HasArraySub,
119135
HasArrayMul,
136+
HasArrayTrueDiv,
120137
Protocol,
121138
):
122139
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)