diff --git a/src/ADNLPModels.jl b/src/ADNLPModels.jl index 546a5293..481724bb 100644 --- a/src/ADNLPModels.jl +++ b/src/ADNLPModels.jl @@ -81,6 +81,11 @@ function ADNLPModel!(model::AbstractNLPModel; kwargs...) end function ADNLPModel(model::AbstractNLPModel; kwargs...) + function model_c(x; model = model) + cx = similar(x, model.meta.ncon) + return cons!(model, x, cx) + end + return if model.meta.nlin > 0 ADNLPModel( x -> obj(model, x), @@ -88,7 +93,7 @@ function ADNLPModel(model::AbstractNLPModel; kwargs...) model.meta.lvar, model.meta.uvar, jac_lin(model, model.meta.x0), - x -> cons(model, x), + model_c, model.meta.lcon, model.meta.ucon; kwargs..., @@ -99,7 +104,7 @@ function ADNLPModel(model::AbstractNLPModel; kwargs...) model.meta.x0, model.meta.lvar, model.meta.uvar, - x -> cons(model, x), + model_c, model.meta.lcon, model.meta.ucon; kwargs..., @@ -110,27 +115,36 @@ end include("nls.jl") function ADNLSModel(model::AbstractNLSModel; kwargs...) + function model_c(x; model = model) + cx = similar(x, model.meta.ncon) + return cons!(model, x, cx) + end + function model_F(x; model = model) + Fx = similar(x, model.nls_meta.nequ) + return residual!(model, x, Fx) + end + return if model.meta.nlin > 0 ADNLSModel( - x -> residual(model, x), + model_F, model.meta.x0, model.nls_meta.nequ, model.meta.lvar, model.meta.uvar, jac_lin(model, model.meta.x0), - x -> cons(model, x), + model_c, model.meta.lcon, model.meta.ucon; kwargs..., ) else ADNLSModel( - x -> residual(model, x), + model_F, model.meta.x0, model.nls_meta.nequ, model.meta.lvar, model.meta.uvar, - x -> cons(model, x), + model_c, model.meta.lcon, model.meta.ucon; kwargs..., diff --git a/src/nlp.jl b/src/nlp.jl index 584af157..7fbac058 100644 --- a/src/nlp.jl +++ b/src/nlp.jl @@ -21,7 +21,7 @@ ADNLPModel( adbackend::ADModelBackend, f, c, -) where {T, S} = ADNLPModel(meta, counters, adbackend, f, Int[], Int[], similar(meta.x0, 0), c) +) where {T, S} = ADNLPModel(meta, counters, adbackend, f, Int[], Int[], S(undef, 0), c) ADNLPModels.show_header(io::IO, nlp::ADNLPModel) = println(io, "ADNLPModel - Model with automatic differentiation backend $(nlp.adbackend)") diff --git a/src/nls.jl b/src/nls.jl index 725b43c1..138c957f 100644 --- a/src/nls.jl +++ b/src/nls.jl @@ -24,7 +24,7 @@ ADNLSModel( F, c, ) where {T, S} = - ADNLSModel(meta, nls_meta, counters, adbackend, F, Int[], Int[], similar(meta.x0, 0), c) + ADNLSModel(meta, nls_meta, counters, adbackend, F, Int[], Int[], S(undef, 0), c) ADNLPModels.show_header(io::IO, nls::ADNLSModel) = println( io,