Skip to content

Commit 3517f4a

Browse files
committed
Rename indmin and indmax to argmin and argmax
argmin and argmax match the mathematical names as well as those used by Numpy. On the contrary, there does not appear to be any precedent for indmin and indmax, and they do not follow any pattern in Julia either.
1 parent 67ee6c6 commit 3517f4a

File tree

15 files changed

+59
-52
lines changed

15 files changed

+59
-52
lines changed

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ This section lists changes that do not have deprecation warnings.
305305
This avoids stack overflows in the common case of definitions like
306306
`f(x, y) = f(promote(x, y)...)` ([#22801]).
307307

308-
* `findmin`, `findmax`, `indmin`, and `indmax` used to always return linear indices.
308+
* `indmin` and `indmax` have been renamed to `argmin` and `argmax`, respectively ([#25654]).
309+
310+
* `findmin`, `findmax`, `argmin`, and `argmax` used to always return linear indices.
309311
They now return `CartesianIndex`es for all but 1-d arrays, and in general return
310312
the `keys` of indexed collections (e.g. dictionaries) ([#22907]).
311313

@@ -1225,3 +1227,4 @@ Command-line option changes
12251227
[#25545]: https://github.com/JuliaLang/julia/issues/25545
12261228
[#25616]: https://github.com/JuliaLang/julia/issues/25616
12271229
[#25634]: https://github.com/JuliaLang/julia/issues/25634
1230+
[#25654]: https://github.com/JuliaLang/julia/issues/25654

base/array.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ function findmin(a)
21152115
end
21162116

21172117
"""
2118-
indmax(itr) -> Integer
2118+
argmax(itr) -> Integer
21192119
21202120
Return the index of the maximum element in a collection. If there are multiple maximal
21212121
elements, then the first one will be returned.
@@ -2124,20 +2124,20 @@ The collection must not be empty.
21242124
21252125
# Examples
21262126
```jldoctest
2127-
julia> indmax([8,0.1,-9,pi])
2127+
julia> argmax([8,0.1,-9,pi])
21282128
1
21292129
2130-
julia> indmax([1,7,7,6])
2130+
julia> argmax([1,7,7,6])
21312131
2
21322132
2133-
julia> indmax([1,7,7,NaN])
2133+
julia> argmax([1,7,7,NaN])
21342134
4
21352135
```
21362136
"""
2137-
indmax(a) = findmax(a)[2]
2137+
argmax(a) = findmax(a)[2]
21382138

21392139
"""
2140-
indmin(itr) -> Integer
2140+
argmin(itr) -> Integer
21412141
21422142
Return the index of the minimum element in a collection. If there are multiple minimal
21432143
elements, then the first one will be returned.
@@ -2146,17 +2146,17 @@ The collection must not be empty.
21462146
21472147
# Examples
21482148
```jldoctest
2149-
julia> indmin([8,0.1,-9,pi])
2149+
julia> argmin([8,0.1,-9,pi])
21502150
3
21512151
2152-
julia> indmin([7,1,1,6])
2152+
julia> argmin([7,1,1,6])
21532153
2
21542154
2155-
julia> indmin([7,1,1,NaN])
2155+
julia> argmin([7,1,1,NaN])
21562156
4
21572157
```
21582158
"""
2159-
indmin(a) = findmin(a)[2]
2159+
argmin(a) = findmin(a)[2]
21602160

21612161
# similar to Matlab's ismember
21622162
"""

base/deprecated.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,8 @@ import .Iterators.enumerate
686686
return p
687687
end
688688

689-
# ease transition for return type change of e.g. indmax due to PR #22907 when used in the
690-
# common pattern `ind2sub(size(a), indmax(a))`
689+
# ease transition for return type change of e.g. argmax due to PR #22907 when used in the
690+
# common pattern `ind2sub(size(a), argmax(a))`
691691
@deprecate(ind2sub(dims::NTuple{N,Integer}, idx::CartesianIndex{N}) where N, Tuple(idx))
692692

693693
@deprecate contains(eq::Function, itr, x) any(y->eq(y,x), itr)
@@ -1616,6 +1616,10 @@ export readandwrite
16161616
# PR #25196
16171617
@deprecate_binding ObjectIdDict IdDict{Any,Any}
16181618

1619+
# PR #25654
1620+
@deprecate indmin argmin
1621+
@deprecate indmax argmax
1622+
16191623
# END 0.7 deprecations
16201624

16211625
# BEGIN 1.0 deprecations

base/exports.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ export
392392
hcat,
393393
hvcat,
394394
indexin,
395-
indmax,
396-
indmin,
395+
argmax,
396+
argmin,
397397
invperm,
398398
invpermute!,
399399
isassigned,

base/pkg/resolve/fieldvalue.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ end
9393
# some hard constraint is being violated
9494
validmax(a::FieldValue) = a.l0 >= 0
9595

96-
# like usual indmax, but favors the highest indices
96+
# like usual argmax, but favors the highest indices
9797
# in case of a tie
98-
function Base.indmax(f::Field)
98+
function Base.argmax(f::Field)
9999
m = typemin(FieldValue)
100100
mi = 0
101101
for j = length(f):-1:1

base/pkg/resolve/maxsum.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ function getsolution(msgs::Messages)
244244
sol = Vector{Int}(uninitialized, np)
245245
for p0 = 1:np
246246
fld0 = fld[p0]
247-
s0 = indmax(fld0)
247+
s0 = argmax(fld0)
248248
if !validmax(fld0[s0])
249249
throw(UnsatError(p0))
250250
end
@@ -387,12 +387,12 @@ function decimate1(p0::Int, graph::Graph, msgs::Messages)
387387

388388
@assert !decimated[p0]
389389
fld0 = fld[p0]
390-
s0 = indmax(fld0)
390+
s0 = argmax(fld0)
391391
# only do the decimation if it is consistent with
392392
# the previously decimated nodes
393393
for p1 in findall(decimated)
394394
haskey(adjdict[p0], p1) || continue
395-
s1 = indmax(fld[p1])
395+
s1 = argmax(fld[p1])
396396
j1 = adjdict[p0][p1]
397397
gmsk[p1][j1][s0,s1] || return false
398398
end

doc/src/base/collections.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ Base.minimum(::Any, ::Any)
9494
Base.minimum!
9595
Base.extrema(::Any)
9696
Base.extrema(::AbstractArray, ::Any)
97-
Base.indmax
98-
Base.indmin
97+
Base.argmax
98+
Base.argmin
9999
Base.findmax(::Any)
100100
Base.findmax(::AbstractArray, ::Any)
101101
Base.findmin(::Any)

stdlib/IterativeEigensolvers/test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ using Test, LinearAlgebra, SparseArrays, Random
4949
si_ind = indmin(imag.(a_evs))
5050
(d, v) = eigs(a, nev=1, which=:SI)
5151
@test d[1] a_evs[si_ind]
52-
lr_ind = indmax(real.(a_evs))
52+
lr_ind = argmax(real.(a_evs))
5353
(d, v) = eigs(a, nev=1, which=:LR)
5454
@test d[1] a_evs[lr_ind]
55-
li_ind = indmax(imag.(a_evs))
55+
li_ind = argmax(imag.(a_evs))
5656
(d, v) = eigs(a, nev=1, which=:LI)
5757
@test d[1] a_evs[li_ind]
5858
end

stdlib/LinearAlgebra/test/blas.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ srand(100)
7171
@testset "iamax" begin
7272
if elty <: Real
7373
x = convert(Vector{elty}, randn(n))
74-
@test BLAS.iamax(x) == indmax(abs.(x))
74+
@test BLAS.iamax(x) == argmax(abs.(x))
7575
else
7676
z = convert(Vector{elty}, complex.(randn(n),randn(n)))
77-
@test BLAS.iamax(z) == indmax(map(x -> abs(real(x)) + abs(imag(x)), z))
77+
@test BLAS.iamax(z) == argmax(map(x -> abs(real(x)) + abs(imag(x)), z))
7878
end
7979
end
8080
@testset "axp(b)y" begin
@@ -109,10 +109,10 @@ srand(100)
109109
@test BLAS.nrm2(b) norm(b)
110110
if elty <: Real
111111
@test BLAS.asum(b) sum(abs.(b))
112-
@test BLAS.iamax(b) indmax(abs.(b))
112+
@test BLAS.iamax(b) argmax(abs.(b))
113113
else
114114
@test BLAS.asum(b) sum(abs.(real(b))) + sum(abs.(imag(b)))
115-
@test BLAS.iamax(b) == indmax(map(x -> abs(real(x)) + abs(imag(x)), b))
115+
@test BLAS.iamax(b) == argmax(map(x -> abs(real(x)) + abs(imag(x)), b))
116116
end
117117
end
118118
# scal

stdlib/SparseArrays/src/SparseArrays.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ import LinearAlgebra: mul!, ldiv!, rdiv!, chol, adjoint!, diag, diff, dot, eig,
1919
import Base: @get!, acos, acosd, acot, acotd, acsch, asech, asin, asind, asinh,
2020
atan, atand, atanh, broadcast!, conj!, cos, cosc, cosd, cosh, cospi, cot,
2121
cotd, coth, count, csc, cscd, csch, done,
22-
exp10, exp2, findprev, findnext, floor, hash, indmin, inv,
22+
exp10, exp2, findprev, findnext, floor, hash, argmin, inv,
2323
log10, log2, next, sec, secd, sech, show,
2424
sin, sinc, sind, sinh, sinpi, squeeze, start, sum, summary, tan,
2525
tand, tanh, trunc, abs, abs2,
2626
broadcast, ceil, complex, conj, convert, copy, copyto!, adjoint,
2727
exp, expm1, findall, findmax, findmin, findnz, float, getindex,
28-
vcat, hcat, hvcat, cat, imag, indmax, kron, length, log, log1p, max, min,
28+
vcat, hcat, hvcat, cat, imag, argmax, kron, length, log, log1p, max, min,
2929
maximum, minimum, one, promote_eltype, real, reshape, rot180,
3030
rotl90, rotr90, round, setindex!, similar, size, transpose,
3131
vec, permute!, map, map!, Array

0 commit comments

Comments
 (0)