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 @@ -106,13 +106,35 @@ def ndim(self) -> int:
106106 ...
107107
108108
109+ class HasShape (Protocol ):
110+ """Protocol for array classes that have a shape attribute."""
111+
112+ @property
113+ def shape (self ) -> tuple [int | None , ...]:
114+ """Shape of the array.
115+
116+ Returns:
117+ tuple[int | None, ...]: array dimensions. An array dimension must be None
118+ if and only if a dimension is unknown.
119+
120+ Notes:
121+ For array libraries having graph-based computational models, array
122+ dimensions may be unknown due to data-dependent operations (e.g.,
123+ boolean indexing; `A[:, B > 0]`) and thus cannot be statically
124+ resolved without knowing array contents.
125+
126+ """
127+ ...
128+
129+
109130@docstring_setter (** _array_docstrings )
110131class Array (
111132 # ------ Attributes -------
112133 HasDType [DType_co ],
113134 HasDevice ,
114135 HasMatrixTranspose ,
115136 HasNDim ,
137+ HasShape ,
116138 # ------ Methods -------
117139 HasArrayNamespace [NS_co ],
118140 op .CanPosSelf ,
You can’t perform that action at this time.
0 commit comments