From c62fdbda9e97294dc2258b055c658591044ef599 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 21 Jun 2018 10:20:44 -0400 Subject: [PATCH] single-argument permutedims(x) --- README.md | 3 +++ src/Compat.jl | 5 +++++ test/runtests.jl | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/README.md b/README.md index d80fadd43..25c5d4093 100644 --- a/README.md +++ b/README.md @@ -288,6 +288,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `squeeze` with `dims` as keyword argument ([#26660]). +* Single-argument `permutedims(x)` for matrices and vectors ([#24839]). + * `fetch` for `Task`s ([#25940]). * `Compat.qr` takes `pivot` as a `Val` _instance_ ([#22475]). @@ -583,6 +585,7 @@ includes this fix. Find the minimum version from there. [#24785]: https://github.com/JuliaLang/julia/issues/24785 [#24808]: https://github.com/JuliaLang/julia/issues/24808 [#24831]: https://github.com/JuliaLang/julia/issues/24831 +[#24839]: https://github.com/JuliaLang/julia/issues/24839 [#24874]: https://github.com/JuliaLang/julia/issues/24874 [#24999]: https://github.com/JuliaLang/julia/issues/24999 [#25012]: https://github.com/JuliaLang/julia/issues/25012 diff --git a/src/Compat.jl b/src/Compat.jl index c81859531..cef0452ae 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1936,6 +1936,11 @@ else end const ⋅ = dot +if VERSION < v"0.7.0-DEV.2956" # julia#24839 + Base.permutedims(A::AbstractMatrix) = permutedims(A, (2,1)) + Base.permutedims(v::AbstractVector) = reshape(v, (1, length(v))) +end + # https://github.com/JuliaLang/julia/pull/27253 @static if VERSION < v"0.7.0-alpha.44" Base.atan(x::Real, y::Real) = atan2(x, y) diff --git a/test/runtests.jl b/test/runtests.jl index c141d9898..099fca978 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1813,6 +1813,10 @@ let sep = Compat.Sys.iswindows() ? ';' : ':' end end +# julia#24839 +@test permutedims([1 2; 3 4]) == [1 3; 2 4] +@test permutedims([1,2,3]) == [1 2 3] + # julia#27401 import Compat: ⋅ @test Compat.opnorm([1 2;3 4]) ≈ 5.464985704219043