Skip to content

Commit 527ec4f

Browse files
authored
Add specification for computing the matrix transpose (#248)
1 parent 8009f8b commit 527ec4f

File tree

2 files changed

+22
-26
lines changed

2 files changed

+22
-26
lines changed

spec/API_specification/linear_algebra_functions.md

+17-21
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,23 @@ The `matmul` function must implement the same semantics as the built-in `@` oper
6060
- if `x1` is a one-dimensional array having shape `(N)`, `x2` is a one-dimensional array having shape `(M)`, and `N != M`.
6161
- if `x1` is an array having shape `(..., M, K)`, `x2` is an array having shape `(..., L, N)`, and `K != L`.
6262

63+
(function-matrix-transpose)=
64+
### matrix_transpose(x, /)
65+
66+
Transposes a matrix (or a stack of matrices) `x`.
67+
68+
#### Parameters
69+
70+
- **x**: _<array>_
71+
72+
- input array having shape `(..., M, N)` and whose innermost two dimensions form `MxN` matrices.
73+
74+
#### Returns
75+
76+
- **out**: _<array>_
77+
78+
- an array containing the transpose for each matrix and having shape `(..., N, M)`. The returned array must have the same data type as `x`.
79+
6380
(function-tensordot)=
6481
### tensordot(x1, x2, /, *, axes=2)
6582

@@ -93,27 +110,6 @@ Returns a tensor contraction of `x1` and `x2` over specific axes.
93110

94111
- an array containing the tensor contraction whose shape consists of the non-contracted axes (dimensions) of the first array `x1`, followed by the non-contracted axes (dimensions) of the second array `x2`. The returned array must have a data type determined by {ref}`type-promotion`.
95112

96-
(function-transpose)=
97-
### transpose(x, /, *, axes=None)
98-
99-
Transposes (or permutes the axes (dimensions)) of an array `x`.
100-
101-
#### Parameters
102-
103-
- **x**: _<array>_
104-
105-
- input array.
106-
107-
- **axes**: _Optional\[ Tuple\[ int, ... ] ]_
108-
109-
- tuple containing a permutation of `(0, 1, ..., N-1)` where `N` is the number of axes (dimensions) of `x`. If `None`, the axes (dimensions) must be permuted in reverse order (i.e., equivalent to setting `axes=(N-1, ..., 1, 0)`). Default: `None`.
110-
111-
#### Returns
112-
113-
- **out**: _<array>_
114-
115-
- an array containing the transpose. The returned array must have the same data type as `x`.
116-
117113
(function-vecdot)=
118114
### vecdot(x1, x2, /, *, axis=None)
119115

spec/extensions/linear_algebra_functions.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ Computes the rank (i.e., number of non-zero singular values) of a matrix (or a s
357357

358358
- an array containing the ranks. The returned array must have a floating-point data type determined by {ref}`type-promotion` and must have shape `(...)` (i.e., must have a shape equal to `shape(x)[:-2]`).
359359

360+
(function-linalg-matrix-transpose)=
361+
### linalg.matrix_transpose(x, /)
362+
363+
Alias for {ref}`function-matrix-transpose`.
364+
360365
(function-linalg-outer)=
361366
### linalg.outer(x1, x2, /)
362367

@@ -562,11 +567,6 @@ Returns the sum along the specified diagonals of a matrix (or a stack of matrice
562567
563568
The returned array must have the same data type as `x`.
564569
565-
(function-linalg-transpose)=
566-
### linalg.transpose(x, /, *, axes=None)
567-
568-
Alias for {ref}`function-transpose`.
569-
570570
(function-linalg-vecdot)=
571571
### linalg.vecdot(x1, x2, /, *, axis=None)
572572

0 commit comments

Comments
 (0)