Skip to content

Commit d5227b5

Browse files
committed
✨ HasSize
Signed-off-by: Nathaniel Starkman <[email protected]>
1 parent e32764f commit d5227b5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/array_api_typing/_array.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,33 @@ def shape(self) -> tuple[int | None, ...]:
132132
...
133133

134134

135+
class HasSize(Protocol):
136+
"""Protocol for array classes that have a size attribute."""
137+
138+
@property
139+
def size(self) -> int | None:
140+
"""Number of elements in an array.
141+
142+
Returns:
143+
int | None: number of elements in an array. The returned value must
144+
be `None` if and only if one or more array dimensions are
145+
unknown.
146+
147+
Notes:
148+
This must equal the product of the array's dimensions.
149+
150+
"""
151+
...
152+
153+
135154
class Array(
136155
# ------ Attributes -------
137156
HasDType[DTypeT_co],
138157
HasDevice,
139158
HasMatrixTranspose,
140159
HasNDim,
141160
HasShape,
161+
HasSize,
142162
# ------- Methods ---------
143163
HasArrayNamespace[NamespaceT_co],
144164
# -------------------------

0 commit comments

Comments
 (0)