File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change 9
9
"HasNDim" ,
10
10
"HasShape" ,
11
11
"HasSize" ,
12
+ "HasTranspose" ,
12
13
"__version__" ,
13
14
"__version_tuple__" ,
14
15
)
22
23
HasNDim ,
23
24
HasShape ,
24
25
HasSize ,
26
+ HasTranspose ,
25
27
)
26
28
from ._version import version as __version__ , version_tuple as __version_tuple__
Original file line number Diff line number Diff line change 7
7
"HasNDim" ,
8
8
"HasShape" ,
9
9
"HasSize" ,
10
+ "HasTranspose" ,
10
11
)
11
12
12
13
from types import ModuleType
@@ -157,6 +158,36 @@ def size(self) -> int | None:
157
158
...
158
159
159
160
161
+ class HasTranspose (Protocol ):
162
+ """Protocol for array classes that support the transpose operation."""
163
+
164
+ @property
165
+ def T (self ) -> Self : # noqa: N802
166
+ """Transpose of the array.
167
+
168
+ The array instance must be two-dimensional. If the array instance is not
169
+ two-dimensional, an error should be raised.
170
+
171
+ Returns:
172
+ Self: two-dimensional array whose first and last dimensions (axes)
173
+ are permuted in reverse order relative to original array. The
174
+ returned array must have the same data type as the original
175
+ array.
176
+
177
+ Notes:
178
+ Limiting the transpose to two-dimensional arrays (matrices) deviates
179
+ from the NumPy et al practice of reversing all axes for arrays
180
+ having more than two-dimensions. This is intentional, as reversing
181
+ all axes was found to be problematic (e.g., conflicting with the
182
+ mathematical definition of a transpose which is limited to matrices;
183
+ not operating on batches of matrices; et cetera). In order to
184
+ reverse all axes, one is recommended to use the functional
185
+ `PermuteDims` interface found in this specification.
186
+
187
+ """
188
+ ...
189
+
190
+
160
191
class Array (
161
192
# ------ Attributes -------
162
193
HasDType [DTypeT_co ],
Original file line number Diff line number Diff line change @@ -74,6 +74,13 @@ _: xpt.HasShape = nparr
74
74
_ : xpt .HasShape = nparr_i32
75
75
_ : xpt .HasShape = nparr_f32
76
76
77
+ # =========================================================
78
+ # `xpt.HasTranspose`
79
+
80
+ _ : xpt .HasTranspose = nparr
81
+ _ : xpt .HasTranspose = nparr_i32
82
+ _ : xpt .HasTranspose = nparr_f32
83
+
77
84
# =========================================================
78
85
# `xpt.Array`
79
86
Original file line number Diff line number Diff line change @@ -85,6 +85,14 @@ _: xpt.HasSize = nparr_i32
85
85
_ : xpt .HasSize = nparr_f32
86
86
_ : xpt .HasSize = nparr_b
87
87
88
+ # =========================================================
89
+ # `xpt.HasTranspose`
90
+
91
+ _ : xpt .HasTranspose = nparr
92
+ _ : xpt .HasTranspose = nparr_i32
93
+ _ : xpt .HasTranspose = nparr_f32
94
+ _ : xpt .HasTranspose = nparr_b
95
+
88
96
# =========================================================
89
97
# `xpt.Array`
90
98
You can’t perform that action at this time.
0 commit comments