From 0d0e025ff51ca97a81be2b45c99de55c695b8f29 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Tue, 23 Jan 2018 01:58:09 -0800 Subject: [PATCH] Add argmin and argmax (#470) * 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..8bd52a62c 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 = indmax + 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]