From 16aa075353a140d120f8a3127a6602653552cc27 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Mon, 22 Jan 2018 15:33:49 -0800 Subject: [PATCH 1/2] Add argmin and argmax --- README.md | 3 +++ src/Compat.jl | 6 ++++++ test/runtests.jl | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/README.md b/README.md index c8b1474ee..048b61fa1 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `find` is now `findall` ([#25545]). +* `indmin` and `indmax` are now `argmin` and `argmax`, respectively ([#25654]). + ## New macros * `@__DIR__` has been added ([#18380]) @@ -484,3 +486,4 @@ includes this fix. Find the minimum version from there. [#25545]: https://github.com/JuliaLang/julia/issues/25545 [#25571]: https://github.com/JuliaLang/julia/issues/25571 [#25629]: https://github.com/JuliaLang/julia/issues/25629 +[#25654]: https://github.com/JuliaLang/julia/issues/25654 diff --git a/src/Compat.jl b/src/Compat.jl index 72ed35f6e..8370b5977 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1304,6 +1304,12 @@ if !isdefined(Base, :findall) export findall end +@static if !isdefined(Base, :argmin) + const argmin = indmin + const argmax = argmax + export argmin, argmax +end + @static if !isdefined(Base, :parentmodule) parentmodule(m::Module) = Base.module_parent(m) parentmodule(f::Function) = Base.function_module(f) diff --git a/test/runtests.jl b/test/runtests.jl index 25c28cc0e..1f3f7ed90 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1168,6 +1168,10 @@ module TestLibdl @test isdefined(@__MODULE__, :Libdl) end +# 0.7.0-DEV.3516 +@test argmax([10,12,9,11]) == 2 +@test argmin([10,12,9,11]) == 3 + # 0.7.0-DEV.3415 @test findall(x -> x==1, [1, 2, 3, 2, 1]) == [1, 5] From 0ded619e6e0643e7e85b1d576dfd176b1cce6655 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Mon, 22 Jan 2018 16:02:06 -0800 Subject: [PATCH 2/2] Whoops (squash me) --- src/Compat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compat.jl b/src/Compat.jl index 8370b5977..8bd52a62c 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1306,7 +1306,7 @@ end @static if !isdefined(Base, :argmin) const argmin = indmin - const argmax = argmax + const argmax = indmax export argmin, argmax end