Skip to content

Commit d41f62c

Browse files
authored
Stop overloading Base.minimum and Base.maximum (#1205)
1 parent c6f69d6 commit d41f62c

File tree

13 files changed

+19
-15
lines changed

13 files changed

+19
-15
lines changed

docs/src/user/minimization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ julia> Optim.minimizer(res)
176176
-0.3333
177177
-1.49994
178178
179-
julia> minimum(res)
179+
julia> Optim.minimum(res)
180180
-2.8333333205768865
181181
```
182182

ext/OptimMOIExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ MOI.get(::Optimizer, ::MOI.DualStatus) = MOI.NO_SOLUTION
421421

422422
function MOI.get(model::Optimizer, attr::MOI.ObjectiveValue)
423423
MOI.check_result_index_bounds(model, attr)
424-
val = minimum(model.results)
424+
val = Optim.minimum(model.results)
425425
if model.sense == MOI.MAX_SENSE
426426
val = -val
427427
end

src/Optim.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ import StatsBase: var
5353
using LinearAlgebra:
5454
LinearAlgebra,
5555
Diagonal,
56-
diag,
5756
Hermitian,
5857
Symmetric,
5958
rmul!,

src/api.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Base.summary(io::IO, r::OptimizationResults) = summary(io, r.method) # might want to do more here than just return summary of the method used
22
minimizer(r::OptimizationResults) = r.minimizer
3-
Base.minimum(r::OptimizationResults) = r.minimum
3+
minimum(r::OptimizationResults) = r.minimum
44
iterations(r::OptimizationResults) = r.iterations
55
iteration_limit_reached(r::OptimizationResults) = r.stopped_by.iterations
66
trace(r::OptimizationResults) =

src/maximize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function maximize(
8080
end
8181

8282
maximizer(r::MaximizationWrapper) = minimizer(res(r))
83-
Base.maximum(r::MaximizationWrapper) = -minimum(res(r))
83+
maximum(r::MaximizationWrapper) = -minimum(res(r))
8484
Base.summary(io::IO, r::MaximizationWrapper) = summary(io, res(r))
8585

8686
for api_method in (

src/multivariate/solvers/constrained/fminbox.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ function optimize(
560560
dfbox.obj.h_calls[1] = 0
561561
end
562562
copyto!(x, minimizer(results))
563-
boxdist = min(minimum(x - l), minimum(u - x))
563+
boxdist = Base.minimum(((xi, li, ui),) -> min(xi - li, ui - xi), zip(x, l, u)) # Base.minimum !== minimum
564564
if show_trace > 0
565565
println()
566566
println("Exiting inner optimizer with x = ", x)

src/multivariate/solvers/constrained/samin.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ function optimize(
304304
else
305305
converge = 1
306306
x_converged = true
307-
x_absΔ = maximum(bounds)
307+
x_absΔ = Base.maximum(bounds) # maximum !== Base.maximum
308308
end
309309
else
310310
f_converged = false

src/multivariate/solvers/first_order/ngmres.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ function update_state!(
355355
Aview = view(state.A, 1:curw, 1:curw)
356356
bview = view(state.b, 1:curw)
357357
# The outer max is to avoid δ=0, which may occur if A=0, e.g. at numerical convergence
358-
δ = method.ϵ0 * max(maximum(diag(Aview)), method.ϵ0)
358+
# Note that Base.maximum !== maximum
359+
δ = method.ϵ0 * max(Base.maximum(@view(Aview[diagind(Aview)])), method.ϵ0)
359360
try
360361
α .= (Aview + δ * I) \ bview
361362
catch e

src/multivariate/solvers/second_order/newton_trust_region.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ work well without these safeguards when the Hessian is not positive definite.
5252
function initial_safeguards(H, gr, delta, lambda)
5353
# equations are on p. 560 of [MORESORENSEN]
5454
T = eltype(gr)
55-
λS = maximum(-diag(H))
55+
λS = -Base.minimum(@view(H[diagind(H)])) # Base.minimum !== minimum
5656
# they state on the first page that ||⋅|| is the Euclidean norm
5757
gr_norm = norm(gr)
5858
Hnorm = opnorm(H, 1)

src/multivariate/solvers/zeroth_order/particle_swarm.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ function initial_state(
110110
end
111111
else
112112
# user did not define number of particles
113-
n_particles = maximum([3, length(initial_x)])
113+
n_particles = max(3, length(initial_x))
114114
end
115115
c1 = T(2)
116116
c2 = T(2)
@@ -193,7 +193,7 @@ function update_state!(f, state::ParticleSwarmState{T}, method::ParticleSwarm) w
193193

194194
if state.iteration == 0
195195
copyto!(state.best_score, state.score)
196-
f.F = minimum(state.score)
196+
f.F = Base.minimum(state.score) # Base.minimum !== minimum
197197
end
198198
f.F = housekeeping!(
199199
state.score,

0 commit comments

Comments
 (0)