Skip to content

Commit 445e057

Browse files
committed
✨: add HasArrayLT protocol to support less-than operator for array classes
1 parent c49f799 commit 445e057

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
@@ -284,6 +284,22 @@ def __rshift__(self, other: Self | int, /) -> Self:
284284
...
285285

286286

287+
class HasArrayLT(Protocol):
288+
"""Protocol for array classes that support the less-than operator."""
289+
290+
def __lt__(self, other: Self | int | float) -> Self:
291+
"""Computes the truth value of ``self_i < other_i`` for each element of an array instance with the respective element of the array other.
292+
293+
Args:
294+
other: other array. Must be compatible with ``self`` (see Broadcasting). Should have a numeric data type.
295+
296+
Returns:
297+
an array containing the element-wise results. The returned array must have a data type of bool.
298+
299+
""" # noqa: E501
300+
...
301+
302+
287303
class Array(
288304
HasArrayNamespace[NS_co],
289305
HasArrayPos,
@@ -302,6 +318,7 @@ class Array(
302318
HasArrayXOr,
303319
HasArrayLShift,
304320
HasArrayRShift,
321+
HasArrayLT,
305322
Protocol,
306323
):
307324
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)