From a4c6f22fe1f7d5160a3f9db96de39b3ecd50c086 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Wed, 11 Jul 2018 08:47:36 +0200 Subject: [PATCH] `mapslices` with `dims` keyword argument (#588) --- README.md | 3 +++ src/Compat.jl | 6 ++++++ test/runtests.jl | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index 8ddeee88b..163cb0b8f 100644 --- a/README.md +++ b/README.md @@ -306,6 +306,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `something` to get the first argument different from `nothing`, unwrapping those of the `Some` type ([#27258]). +* `mapslices` with `dims` keyword argument ([#27828]). + ## Renaming * `Display` is now `AbstractDisplay` ([#24831]). @@ -658,3 +660,4 @@ includes this fix. Find the minimum version from there. [#27258]: https://github.com/JuliaLang/julia/issues/27258 [#27298]: https://github.com/JuliaLang/julia/issues/27298 [#27401]: https://github.com/JuliaLang/julia/issues/27401 +[#27828]: https://github.com/JuliaLang/julia/issues/27828 diff --git a/src/Compat.jl b/src/Compat.jl index e3ad4e042..d201c6e04 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1966,6 +1966,12 @@ end Base.split(s, splitter; limit=limit, keep=keepempty) end +# https://github.com/JuliaLang/julia/pull/27828 +if VERSION < v"0.7.0-beta.73" + Base.mapslices(f, A::AbstractArray; dims=error("required keyword argument `dims` missing")) = + mapslices(f, A, dims) +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index c2788d080..1223b891a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1896,4 +1896,14 @@ let @test Compat.split(str, r"\.+:\.+"; limit=3, keepempty=true) == ["a","ba","cba.:.:.dcba.:."] end +# 0.7.0-beta.73 +let a = rand(5,5) + s = mapslices(sort, a, dims=[1]) + S = mapslices(sort, a, dims=[2]) + for i = 1:5 + @test s[:,i] == sort(a[:,i]) + @test vec(S[i,:]) == sort(vec(a[i,:])) + end +end + nothing