Skip to content

Commit

Permalink
fix Base.warn_once (#2568)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot authored Apr 21, 2021
1 parent 801c03f commit 2c2beb8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1907,9 +1907,8 @@ function register(
fprimeprime,
)
else
autodiff == false || Base.warn_once(
"autodiff=true ignored since gradient is already provided.",
)
autodiff == false ||
@warn("autodiff=true ignored since gradient is already provided.")
m.nlp_data.largest_user_input_dimension =
max(m.nlp_data.largest_user_input_dimension, dimension)
d = _UserFunctionEvaluator(
Expand Down
12 changes: 12 additions & 0 deletions test/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ function test_multivariate()
@test MOI.eval_objective(d, x) == 8.0
end

function test_multivariate_register_warn()
model = Model()
g(x, y) = x^2 + y^2
function ∇g(g::Vector{T}, x::T, y::T) where {T<:Real}
g[1] = y
g[2] = x
return
end
@test_logs (:warn,) register(model, :g, 2, g, ∇g; autodiff = true)
end

function test_multivariate_existing_nlpdata()
model = Model()
@variable(model, x >= 0)
Expand Down Expand Up @@ -150,6 +161,7 @@ end
test_multivariate()
test_multivariate_existing_nlpdata()
test_multivariate_redefine()
test_multivariate_register_warn()
end

@testset "Nonlinear" begin
Expand Down

0 comments on commit 2c2beb8

Please sign in to comment.