Skip to content

Commit f04da40

Browse files
committed
✨: add HasArrayAnd protocol to support bitwise AND operator for array classes
1 parent 80f2a68 commit f04da40

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
@@ -204,6 +204,22 @@ def __invert__(self) -> Self:
204204
...
205205

206206

207+
class HasArrayAnd(Protocol):
208+
"""Evaluates ``self_i & other_i`` for each element of an array instance with the respective element of the array other.""" # noqa: E501
209+
210+
def __and__(self, other: Self | int | float, /) -> Self:
211+
"""Calculates the bitwise AND for each element of an array instance with the respective element of the array other.
212+
213+
Args:
214+
other: operand array. Must be compatible with self (see Broadcasting). Should have an integer data type.
215+
216+
Returns:
217+
an array containing the element-wise bitwise ANDs. The returned array must have a data type determined by Type Promotion Rules.
218+
219+
""" # noqa: E501
220+
...
221+
222+
207223
class Array(
208224
HasArrayNamespace[NS_co],
209225
HasArrayPos,
@@ -217,6 +233,7 @@ class Array(
217233
HasArrayPow,
218234
HasArrayMatmul,
219235
HasArrayInvert,
236+
HasArrayAnd,
220237
Protocol,
221238
):
222239
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)