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 77 "HasDevice" ,
88 "HasMatrixTranspose" ,
99 "HasNDim" ,
10+ "HasShape" ,
1011 "__version__" ,
1112 "__version_tuple__" ,
1213)
1819 HasDType ,
1920 HasMatrixTranspose ,
2021 HasNDim ,
22+ HasShape ,
2123)
2224from ._version import version as __version__ , version_tuple as __version_tuple__
Original file line number Diff line number Diff line change 55 "HasDevice" ,
66 "HasMatrixTranspose" ,
77 "HasNDim" ,
8+ "HasShape" ,
89)
910
1011from types import ModuleType
@@ -115,6 +116,27 @@ def ndim(self) -> int:
115116 ...
116117
117118
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+
118140class Array (
119141 # ------ Attributes -------
120142 HasDType [DTypeT_co ],
Original file line number Diff line number Diff line change @@ -60,6 +60,13 @@ _: xpt.HasNDim = nparr
6060_ : xpt .HasNDim = nparr_i32
6161_ : xpt .HasNDim = nparr_f32
6262
63+ # =========================================================
64+ # `xpt.HasShape`
65+
66+ _ : xpt .HasShape = nparr
67+ _ : xpt .HasShape = nparr_i32
68+ _ : xpt .HasShape = nparr_f32
69+
6370# =========================================================
6471# `xpt.Array`
6572
Original file line number Diff line number Diff line change @@ -69,6 +69,14 @@ _: xpt.HasNDim = nparr_i32
6969_ : xpt .HasNDim = nparr_f32
7070_ : xpt .HasNDim = nparr_b
7171
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+
7280# =========================================================
7381# `xpt.Array`
7482
You can’t perform that action at this time.
0 commit comments