@@ -130,6 +130,35 @@ def size(self) -> int | None:
130
130
...
131
131
132
132
133
+ class HasTranspose (Protocol ):
134
+ """Protocol for array classes that support the transpose operation."""
135
+
136
+ def T (self ) -> Self : # noqa: N802
137
+ """Transpose of the array.
138
+
139
+ The array instance must be two-dimensional. If the array instance is not
140
+ two-dimensional, an error should be raised.
141
+
142
+ Returns:
143
+ Self: two-dimensional array whose first and last dimensions (axes)
144
+ are permuted in reverse order relative to original array. The
145
+ returned array must have the same data type as the original
146
+ array.
147
+
148
+ Notes:
149
+ Limiting the transpose to two-dimensional arrays (matrices) deviates
150
+ from the NumPy et al practice of reversing all axes for arrays
151
+ having more than two-dimensions. This is intentional, as reversing
152
+ all axes was found to be problematic (e.g., conflicting with the
153
+ mathematical definition of a transpose which is limited to matrices;
154
+ not operating on batches of matrices; et cetera). In order to
155
+ reverse all axes, one is recommended to use the functional
156
+ `PermuteDims` interface found in this specification.
157
+
158
+ """
159
+ ...
160
+
161
+
133
162
# ============================================================================
134
163
135
164
@@ -583,6 +612,7 @@ class Array(
583
612
HasNDim ,
584
613
HasShape ,
585
614
HasSize ,
615
+ HasTranspose ,
586
616
# ------ Methods -------
587
617
HasArrayNamespace [NS_co ],
588
618
CanArrayPos ,
0 commit comments