From 12e6882ad5198c4c44ec8ae1f94fd4fa149d82fb Mon Sep 17 00:00:00 2001 From: Andy Nowacki Date: Wed, 22 Aug 2018 13:17:40 +0100 Subject: [PATCH] Define argmin and argmax for Tuples Fixes #621. --- src/Compat.jl | 2 ++ test/runtests.jl | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Compat.jl b/src/Compat.jl index 345435aa8..5d1f5bdfd 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1400,9 +1400,11 @@ end argmin(x::AbstractArray) = CartesianIndex(ind2sub(x, indmin(x))) argmin(x::AbstractVector) = indmin(x) argmin(x::Associative) = first(Iterators.drop(keys(x), indmin(values(x))-1)) + argmin(x::Tuple) = indmin(x) argmax(x::AbstractArray) = CartesianIndex(ind2sub(x, indmax(x))) argmax(x::AbstractVector) = indmax(x) argmax(x::Associative) = first(Iterators.drop(keys(x), indmax(values(x))-1)) + argmax(x::Tuple) = indmax(x) end export argmin, argmax end diff --git a/test/runtests.jl b/test/runtests.jl index 36b5f9755..115a2ef7f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1231,9 +1231,11 @@ end @test argmax([10,12,9,11]) == 2 @test argmax([10 12; 9 11]) == CartesianIndex(1, 2) @test argmax(Dict(:z=>10, :y=>12, :x=>9, :w=>11)) == :y +@test argmax((-5, 6, 10)) == 3 @test argmin([10,12,9,11]) == 3 @test argmin([10 12; 9 11]) == CartesianIndex(2, 1) @test argmin(Dict(:z=>10, :y=>12, :x=>9, :w=>11)) == :x +@test argmin((1.0, -3, 0.f0)) == 2 # 0.7.0-DEV.3415 @test findall(x -> x==1, [1, 2, 3, 2, 1]) == [1, 5]