From 665279aedb18501938c934d46aa593a26a506b3e Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Fri, 23 Oct 2020 23:08:28 +0200 Subject: [PATCH] =?UTF-8?q?add=20'=E1=B5=80=20postfix=20operator=20for=20t?= =?UTF-8?q?ranspose=20(#38062)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NEWS.md | 1 + base/exports.jl | 1 + base/operators.jl | 1 + stdlib/LinearAlgebra/src/adjtrans.jl | 12 ++++++++++++ test/operators.jl | 3 +++ 5 files changed, 18 insertions(+) diff --git a/NEWS.md b/NEWS.md index a8401633fe11a..0b7cbb37205ba 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ------------------------ diff --git a/base/exports.jl b/base/exports.jl index 287866ca59503..3e7e6ce7647e4 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -466,6 +466,7 @@ export # linear algebra var"'", # to enable syntax a' for adjoint adjoint, + var"'ᵀ", transpose, kron, kron!, diff --git a/base/operators.jl b/base/operators.jl index bdf1735bad884..55de805671a5f 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -547,6 +547,7 @@ end function kron! end const var"'" = adjoint +const var"'ᵀ" = transpose """ \\(x, y) diff --git a/stdlib/LinearAlgebra/src/adjtrans.jl b/stdlib/LinearAlgebra/src/adjtrans.jl index c9f7326116bff..456441163f9de 100644 --- a/stdlib/LinearAlgebra/src/adjtrans.jl +++ b/stdlib/LinearAlgebra/src/adjtrans.jl @@ -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, @@ -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] @@ -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) diff --git a/test/operators.jl b/test/operators.jl index fb0af5b552047..a806c5cead5df 100644 --- a/test/operators.jl +++ b/test/operators.jl @@ -243,3 +243,6 @@ end @test gt5(6) && !gt5(5) @test lt5(4) && !lt5(5) end + +a = rand(3, 3) +@test transpose(a) === a'ᵀ