Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'ᵀ postfix operator for transpose #38062

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,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 @@ -464,6 +464,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'ᵀ