Skip to content

Commit

Permalink
add 'ᵀ postfix operator for transpose (#38062)
Browse files Browse the repository at this point in the history
  • Loading branch information
simeonschaub authored Oct 23, 2020
1 parent 5faa51b commit 665279a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ New library features
inserting or consuming the first dimension depending on the ratio of `sizeof(T)` and `sizeof(S)`.
* New `append!(vector, collections...)` and `prepend!(vector, collections...)` methods accept multiple
collections to be appended or prepended ([#36227]).
* The postfix operator `'ᵀ` can now be used as an alias for `transpose` ([#38043]).

Standard library changes
------------------------
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ export
# linear algebra
var"'", # to enable syntax a' for adjoint
adjoint,
var"'ᵀ",
transpose,
kron,
kron!,
Expand Down
1 change: 1 addition & 0 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ end
function kron! end

const var"'" = adjoint
const var"'ᵀ" = transpose

"""
\\(x, y)
Expand Down
12 changes: 12 additions & 0 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ julia> x'x
adjoint(A::AbstractVecOrMat) = Adjoint(A)

"""
A'ᵀ
transpose(A)
Lazy transpose. Mutating the returned object should appropriately mutate `A`. Often,
Expand All @@ -145,6 +146,9 @@ that this operation is recursive.
This operation is intended for linear algebra usage - for general data manipulation see
[`permutedims`](@ref Base.permutedims), which is non-recursive.
!!! compat "Julia 1.6"
The postfix operator `'ᵀ` requires Julia 1.6.
# Examples
```jldoctest
julia> A = [3+2im 9+2im; 8+7im 4+6im]
Expand All @@ -156,6 +160,14 @@ julia> transpose(A)
2×2 Transpose{Complex{Int64}, Matrix{Complex{Int64}}}:
3+2im 8+7im
9+2im 4+6im
julia> x = [3, 4im]
2-element Vector{Complex{Int64}}:
3 + 0im
0 + 4im
julia> x'ᵀx
-7 + 0im
```
"""
transpose(A::AbstractVecOrMat) = Transpose(A)
Expand Down
3 changes: 3 additions & 0 deletions test/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,6 @@ end
@test gt5(6) && !gt5(5)
@test lt5(4) && !lt5(5)
end

a = rand(3, 3)
@test transpose(a) === a'

0 comments on commit 665279a

Please sign in to comment.