Skip to content

Commit 3ee1591

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

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
@@ -50,9 +50,28 @@ def __pos__(self) -> Self:
5050
...
5151

5252

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

0 commit comments

Comments
 (0)