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