Skip to content

Commit e624509

Browse files
committed
feat: HasSize
Signed-off-by: Nathaniel Starkman <[email protected]>
1 parent 1aee6e0 commit e624509

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
@@ -127,6 +127,25 @@ def shape(self) -> tuple[int | None, ...]:
127127
...
128128

129129

130+
class HasSize(Protocol):
131+
"""Protocol for array classes that have a size attribute."""
132+
133+
@property
134+
def size(self) -> int | None:
135+
"""Number of elements in an array.
136+
137+
Returns:
138+
int | None: number of elements in an array. The returned value must
139+
be `None` if and only if one or more array dimensions are
140+
unknown.
141+
142+
Notes:
143+
This must equal the product of the array's dimensions.
144+
145+
"""
146+
...
147+
148+
130149
@docstring_setter(**_array_docstrings)
131150
class Array(
132151
# ------ Attributes -------
@@ -135,6 +154,7 @@ class Array(
135154
HasMatrixTranspose,
136155
HasNDim,
137156
HasShape,
157+
HasSize,
138158
# ------ Methods -------
139159
HasArrayNamespace[NS_co],
140160
op.CanPosSelf,

0 commit comments

Comments
 (0)