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