File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Expand file tree Collapse file tree 4 files changed +39
-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
@@ -116,6 +117,27 @@ def ndim(self) -> int:
116
117
...
117
118
118
119
120
+ class HasShape (Protocol ):
121
+ """Protocol for array classes that have a shape attribute."""
122
+
123
+ @property
124
+ def shape (self ) -> tuple [int | None , ...]:
125
+ """Shape of the array.
126
+
127
+ Returns:
128
+ tuple[int | None, ...]: array dimensions. An array dimension must be None
129
+ if and only if a dimension is unknown.
130
+
131
+ Notes:
132
+ For array libraries having graph-based computational models, array
133
+ dimensions may be unknown due to data-dependent operations (e.g.,
134
+ boolean indexing; `A[:, B > 0]`) and thus cannot be statically
135
+ resolved without knowing array contents.
136
+
137
+ """
138
+ ...
139
+
140
+
119
141
class Array (
120
142
# ------ Attributes -------
121
143
HasDType [DTypeT_co ],
Original file line number Diff line number Diff line change @@ -60,6 +60,13 @@ _: xpt.HasNDim = nparr
60
60
_ : xpt .HasNDim = nparr_i32
61
61
_ : xpt .HasNDim = nparr_f32
62
62
63
+ # =========================================================
64
+ # `xpt.HasShape`
65
+
66
+ _ : xpt .HasShape = nparr
67
+ _ : xpt .HasShape = nparr_i32
68
+ _ : xpt .HasShape = nparr_f32
69
+
63
70
# =========================================================
64
71
# `xpt.Array`
65
72
Original file line number Diff line number Diff line change @@ -69,6 +69,14 @@ _: xpt.HasNDim = nparr_i32
69
69
_ : xpt .HasNDim = nparr_f32
70
70
_ : xpt .HasNDim = nparr_b
71
71
72
+ # =========================================================
73
+ # `xpt.HasShape`
74
+
75
+ _ : xpt .HasShape = nparr
76
+ _ : xpt .HasShape = nparr_i32
77
+ _ : xpt .HasShape = nparr_f32
78
+ _ : xpt .HasShape = nparr_b
79
+
72
80
# =========================================================
73
81
# `xpt.Array`
74
82
You can’t perform that action at this time.
0 commit comments