Skip to content

Commit 836b386

Browse files
committed
✨: add CanArrayNeg protocol
Support unary minus operator. Signed-off-by: Nathaniel Starkman <[email protected]>
1 parent b2e998a commit 836b386

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,28 @@ def __pos__(self) -> Self:
4848
...
4949

5050

51+
class CanArrayNeg(Protocol):
52+
"""Protocol for array classes that support the unary minus operator."""
53+
54+
def __neg__(self) -> Self:
55+
"""Evaluates `-self_i` for each element of an array instance.
56+
57+
Returns:
58+
Self: an array containing the evaluated result for each element in
59+
self. The returned array must have a data type determined by Type
60+
Promotion Rules.
61+
62+
See Also:
63+
array_api_typing.Negative
64+
65+
"""
66+
...
67+
68+
5169
class Array(
5270
HasArrayNamespace[NS_co],
5371
CanArrayPos,
72+
CanArrayNeg,
5473
Protocol,
5574
):
5675
"""Array API specification for array object attributes and methods."""

0 commit comments

Comments
 (0)