File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -111,12 +111,34 @@ def ndim(self) -> int:
111
111
...
112
112
113
113
114
+ class HasShape (Protocol ):
115
+ """Protocol for array classes that have a shape attribute."""
116
+
117
+ @property
118
+ def shape (self ) -> tuple [int | None , ...]:
119
+ """Shape of the array.
120
+
121
+ Returns:
122
+ tuple[int | None, ...]: array dimensions. An array dimension must be None
123
+ if and only if a dimension is unknown.
124
+
125
+ Notes:
126
+ For array libraries having graph-based computational models, array
127
+ dimensions may be unknown due to data-dependent operations (e.g.,
128
+ boolean indexing; `A[:, B > 0]`) and thus cannot be statically
129
+ resolved without knowing array contents.
130
+
131
+ """
132
+ ...
133
+
134
+
114
135
class Array (
115
136
# ------ Attributes -------
116
137
HasDType [DTypeT_co ],
117
138
HasDevice ,
118
139
HasMatrixTranspose ,
119
140
HasNDim ,
141
+ HasShape ,
120
142
# ------- Methods ---------
121
143
HasArrayNamespace [NamespaceT_co ],
122
144
# -------------------------
Original file line number Diff line number Diff line change @@ -67,3 +67,7 @@ _: xpt.Array[dtype[Any]] = x_i32.mT
67
67
# Check Attribute `.ndim`
68
68
_ : int = x_f32 .ndim
69
69
_ : int = x_i32 .ndim
70
+
71
+ # Check Attribute `.shape`
72
+ _ : tuple [int | None , ...] = x_f32 .shape
73
+ _ : tuple [int | None , ...] = x_i32 .shape
Original file line number Diff line number Diff line change @@ -76,3 +76,8 @@ _: xpt.Array[np.dtype[B]] = x_b.mT
76
76
_ : int = x_f32 .ndim
77
77
_ : int = x_i32 .ndim
78
78
_ : int = x_b .ndim
79
+
80
+ # Check Attribute `.shape`
81
+ _ : tuple [int | None , ...] = x_f32 .shape
82
+ _ : tuple [int | None , ...] = x_i32 .shape
83
+ _ : tuple [int | None , ...] = x_b .shape
You can’t perform that action at this time.
0 commit comments