Skip to content

Commit 665279a

Browse files
authored
add 'ᵀ postfix operator for transpose (#38062)
1 parent 5faa51b commit 665279a

File tree

5 files changed

+18
-0
lines changed

5 files changed

+18
-0
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ New library features
106106
inserting or consuming the first dimension depending on the ratio of `sizeof(T)` and `sizeof(S)`.
107107
* New `append!(vector, collections...)` and `prepend!(vector, collections...)` methods accept multiple
108108
collections to be appended or prepended ([#36227]).
109+
* The postfix operator `'ᵀ` can now be used as an alias for `transpose` ([#38043]).
109110

110111
Standard library changes
111112
------------------------

base/exports.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ export
466466
# linear algebra
467467
var"'", # to enable syntax a' for adjoint
468468
adjoint,
469+
var"'ᵀ",
469470
transpose,
470471
kron,
471472
kron!,

base/operators.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,7 @@ end
547547
function kron! end
548548

549549
const var"'" = adjoint
550+
const var"'ᵀ" = transpose
550551

551552
"""
552553
\\(x, y)

stdlib/LinearAlgebra/src/adjtrans.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ julia> x'x
136136
adjoint(A::AbstractVecOrMat) = Adjoint(A)
137137

138138
"""
139+
A'ᵀ
139140
transpose(A)
140141
141142
Lazy transpose. Mutating the returned object should appropriately mutate `A`. Often,
@@ -145,6 +146,9 @@ that this operation is recursive.
145146
This operation is intended for linear algebra usage - for general data manipulation see
146147
[`permutedims`](@ref Base.permutedims), which is non-recursive.
147148
149+
!!! compat "Julia 1.6"
150+
The postfix operator `'ᵀ` requires Julia 1.6.
151+
148152
# Examples
149153
```jldoctest
150154
julia> A = [3+2im 9+2im; 8+7im 4+6im]
@@ -156,6 +160,14 @@ julia> transpose(A)
156160
2×2 Transpose{Complex{Int64}, Matrix{Complex{Int64}}}:
157161
3+2im 8+7im
158162
9+2im 4+6im
163+
164+
julia> x = [3, 4im]
165+
2-element Vector{Complex{Int64}}:
166+
3 + 0im
167+
0 + 4im
168+
169+
julia> x'ᵀx
170+
-7 + 0im
159171
```
160172
"""
161173
transpose(A::AbstractVecOrMat) = Transpose(A)

test/operators.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,6 @@ end
243243
@test gt5(6) && !gt5(5)
244244
@test lt5(4) && !lt5(5)
245245
end
246+
247+
a = rand(3, 3)
248+
@test transpose(a) === a'

0 commit comments

Comments
 (0)