Skip to content

Commit cbe6dbb

Browse files
committed
✨: add HasArrayLShift protocol to support left shift operator for array classes
1 parent 12ace72 commit cbe6dbb

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

src/array_api_typing/_array.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,22 @@ def __xor__(self, other: Self | int | float, /) -> Self:
252252
...
253253

254254

255+
class HasArrayLShift(Protocol):
256+
"""Protocol for array classes that support the left shift operator."""
257+
258+
def __lshift__(self, other: Self | int, /) -> Self:
259+
"""Calculates the left shift for each element of an array instance with the respective element of the array other.
260+
261+
Args:
262+
other: operand array. Must be compatible with self (see Broadcasting). Should have an integer data type.
263+
264+
Returns:
265+
an array containing the element-wise left shifts. The returned array must have a data type determined by Type Promotion Rules.
266+
267+
""" # noqa: E501
268+
...
269+
270+
255271
class Array(
256272
HasArrayNamespace[NS_co],
257273
HasArrayPos,
@@ -268,6 +284,7 @@ class Array(
268284
HasArrayAnd,
269285
HasArrayOr,
270286
HasArrayXOr,
287+
HasArrayLShift,
271288
Protocol,
272289
):
273290
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)