File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,27 @@ def ndim(self) -> int:
90
90
...
91
91
92
92
93
+ class HasShape (Protocol ):
94
+ """Protocol for array classes that have a shape attribute."""
95
+
96
+ @property
97
+ def shape (self ) -> tuple [int | None , ...]:
98
+ """Shape of the array.
99
+
100
+ Returns:
101
+ tuple[int | None, ...]: array dimensions. An array dimension must be None
102
+ if and only if a dimension is unknown.
103
+
104
+ Notes:
105
+ For array libraries having graph-based computational models, array
106
+ dimensions may be unknown due to data-dependent operations (e.g.,
107
+ boolean indexing; `A[:, B > 0]`) and thus cannot be statically
108
+ resolved without knowing array contents.
109
+
110
+ """
111
+ ...
112
+
113
+
93
114
# ============================================================================
94
115
95
116
@@ -541,6 +562,7 @@ class Array(
541
562
HasDevice ,
542
563
HasMatrixTranspose ,
543
564
HasNDim ,
565
+ HasShape ,
544
566
# ------ Methods -------
545
567
HasArrayNamespace [NS_co ],
546
568
CanArrayPos ,
You can’t perform that action at this time.
0 commit comments