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, ...]:
132
132
...
133
133
134
134
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
+
135
154
class Array (
136
155
# ------ Attributes -------
137
156
HasDType [DTypeT_co ],
138
157
HasDevice ,
139
158
HasMatrixTranspose ,
140
159
HasNDim ,
141
160
HasShape ,
161
+ HasSize ,
142
162
# ------- Methods ---------
143
163
HasArrayNamespace [NamespaceT_co ],
144
164
# -------------------------
Original file line number Diff line number Diff line change @@ -81,3 +81,8 @@ _: int = x_b.ndim
81
81
_ : tuple [int | None , ...] = x_f32 .shape
82
82
_ : tuple [int | None , ...] = x_i32 .shape
83
83
_ : 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