File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff 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+
135154class Array (
136155 # ------ Attributes -------
137156 HasDType [DTypeT_co ],
138157 HasDevice ,
139158 HasMatrixTranspose ,
140159 HasNDim ,
141160 HasShape ,
161+ HasSize ,
142162 # ------- Methods ---------
143163 HasArrayNamespace [NamespaceT_co ],
144164 # -------------------------
Original file line number Diff line number Diff line change @@ -81,3 +81,8 @@ _: int = x_b.ndim
8181_ : tuple [int | None , ...] = x_f32 .shape
8282_ : tuple [int | None , ...] = x_i32 .shape
8383_ : tuple [int | None , ...] = x_b .shape
84+
85+ # Check Attribute `.size`
86+ _ : int | None = x_f32 .size
87+ _ : int | None = x_i32 .size
88+ _ : int | None = x_b .size
You can’t perform that action at this time.
0 commit comments