File tree Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Expand file tree Collapse file tree 4 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 7
7
"HasDevice" ,
8
8
"HasMatrixTranspose" ,
9
9
"HasNDim" ,
10
+ "HasShape" ,
10
11
"__version__" ,
11
12
"__version_tuple__" ,
12
13
)
18
19
HasDType ,
19
20
HasMatrixTranspose ,
20
21
HasNDim ,
22
+ HasShape ,
21
23
)
22
24
from ._version import version as __version__ , version_tuple as __version_tuple__
Original file line number Diff line number Diff line change 5
5
"HasDevice" ,
6
6
"HasMatrixTranspose" ,
7
7
"HasNDim" ,
8
+ "HasShape" ,
8
9
)
9
10
10
11
from types import ModuleType
@@ -115,12 +116,34 @@ def ndim(self) -> int:
115
116
...
116
117
117
118
119
+ class HasShape (Protocol ):
120
+ """Protocol for array classes that have a shape attribute."""
121
+
122
+ @property
123
+ def shape (self ) -> tuple [int | None , ...]:
124
+ """Shape of the array.
125
+
126
+ Returns:
127
+ tuple[int | None, ...]: array dimensions. An array dimension must be None
128
+ if and only if a dimension is unknown.
129
+
130
+ Notes:
131
+ For array libraries having graph-based computational models, array
132
+ dimensions may be unknown due to data-dependent operations (e.g.,
133
+ boolean indexing; `A[:, B > 0]`) and thus cannot be statically
134
+ resolved without knowing array contents.
135
+
136
+ """
137
+ ...
138
+
139
+
118
140
class Array (
119
141
# ------ Attributes -------
120
142
HasDType [DTypeT_co ],
121
143
HasDevice ,
122
144
HasMatrixTranspose ,
123
145
HasNDim ,
146
+ HasShape ,
124
147
# ------- Methods ---------
125
148
HasArrayNamespace [NamespaceT_co ],
126
149
# -------------------------
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