Skip to content

Commit

Permalink
Add argmin and argmax (#470)
Browse files Browse the repository at this point in the history
* Add argmin and argmax
  • Loading branch information
ararslan authored and fredrikekre committed Jan 23, 2018
1 parent d79a809 commit 0d0e025
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit 0d0e025

Please sign in to comment.