Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add argmin and argmax #470

Merged
merged 2 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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