Skip to content

Commit 6fd91be

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

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

113113

114+
class HasSize(Protocol):
115+
"""Protocol for array classes that have a size attribute."""
116+
117+
@property
118+
def size(self) -> int | None:
119+
"""Number of elements in an array.
120+
121+
Returns:
122+
int | None: number of elements in an array. The returned value must
123+
be `None` if and only if one or more array dimensions are
124+
unknown.
125+
126+
Notes:
127+
This must equal the product of the array's dimensions.
128+
129+
"""
130+
...
131+
132+
114133
# ============================================================================
115134

116135

@@ -563,6 +582,7 @@ class Array(
563582
HasMatrixTranspose,
564583
HasNDim,
565584
HasShape,
585+
HasSize,
566586
# ------ Methods -------
567587
HasArrayNamespace[NS_co],
568588
CanArrayPos,

0 commit comments

Comments
 (0)