@@ -151,6 +151,36 @@ def size(self) -> int | None:
151
151
...
152
152
153
153
154
+ class HasTranspose (Protocol ):
155
+ """Protocol for array classes that support the transpose operation."""
156
+
157
+ @property
158
+ def T (self ) -> Self : # noqa: N802
159
+ """Transpose of the array.
160
+
161
+ The array instance must be two-dimensional. If the array instance is not
162
+ two-dimensional, an error should be raised.
163
+
164
+ Returns:
165
+ Self: two-dimensional array whose first and last dimensions (axes)
166
+ are permuted in reverse order relative to original array. The
167
+ returned array must have the same data type as the original
168
+ array.
169
+
170
+ Notes:
171
+ Limiting the transpose to two-dimensional arrays (matrices) deviates
172
+ from the NumPy et al practice of reversing all axes for arrays
173
+ having more than two-dimensions. This is intentional, as reversing
174
+ all axes was found to be problematic (e.g., conflicting with the
175
+ mathematical definition of a transpose which is limited to matrices;
176
+ not operating on batches of matrices; et cetera). In order to
177
+ reverse all axes, one is recommended to use the functional
178
+ `PermuteDims` interface found in this specification.
179
+
180
+ """
181
+ ...
182
+
183
+
154
184
class Array (
155
185
# ------ Attributes -------
156
186
HasDType [DTypeT_co ],
@@ -159,6 +189,7 @@ class Array(
159
189
HasNDim ,
160
190
HasShape ,
161
191
HasSize ,
192
+ HasTranspose ,
162
193
# ------- Methods ---------
163
194
HasArrayNamespace [NamespaceT_co ],
164
195
# -------------------------
0 commit comments