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 @@ -112,12 +112,34 @@ def ndim(self) -> int:
112112 ...
113113
114114
115+ class HasShape (Protocol ):
116+ """Protocol for array classes that have a shape attribute."""
117+
118+ @property
119+ def shape (self ) -> tuple [int | None , ...]:
120+ """Shape of the array.
121+
122+ Returns:
123+ tuple[int | None, ...]: array dimensions. An array dimension must be None
124+ if and only if a dimension is unknown.
125+
126+ Notes:
127+ For array libraries having graph-based computational models, array
128+ dimensions may be unknown due to data-dependent operations (e.g.,
129+ boolean indexing; `A[:, B > 0]`) and thus cannot be statically
130+ resolved without knowing array contents.
131+
132+ """
133+ ...
134+
135+
115136class Array (
116137 # ------ Attributes -------
117138 HasDType [DTypeT_co ],
118139 HasDevice ,
119140 HasMatrixTranspose ,
120141 HasNDim ,
142+ HasShape ,
121143 # ------- Methods ---------
122144 HasArrayNamespace [NamespaceT_co ],
123145 # -------------------------
Original file line number Diff line number Diff line change @@ -67,3 +67,7 @@ _: xpt.Array[dtype[Any]] = x_i32.mT
6767# Check Attribute `.ndim`
6868_ : int = x_f32 .ndim
6969_ : 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
7676_ : int = x_f32 .ndim
7777_ : int = x_i32 .ndim
7878_ : 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