Skip to content

Commit

Permalink
Pre-allocate jac operator (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot authored Jun 27, 2023
1 parent bb1612f commit b303dbb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ mutable struct PercivalSolver{V, Op} <: AbstractOptimizationSolver
gx::V
gL::V
gp::V
Jv::V
Jtv::V
Jx::Op
cgls_solver::CglsSolver
Expand All @@ -163,15 +164,17 @@ function PercivalSolver(
gx = V(undef, nvar)
gL = V(undef, nvar)
gp = V(undef, nvar)

Jv = V(undef, ncon)
Jtv = V(undef, nvar)

Jx = jac_op(nlp, x) # jac_op!(nlp, x, Jv, Jtv)
Jx = jac_op!(nlp, x, Jv, Jtv)
cgls_solver = CglsSolver(Jx', gx)

sub_pb = AugLagModel(nlp, V(undef, ncon), T(0), x, T(0), V(undef, ncon))
sub_solver = TronSolver(subproblem_modifier(sub_pb); kwargs...)
sub_stats = GenericExecutionStats(sub_pb)
return PercivalSolver{V, typeof(Jx)}(x, y, gx, gL, gp, Jtv, Jx, cgls_solver, sub_pb, sub_solver, sub_stats)
return PercivalSolver{V, typeof(Jx)}(x, y, gx, gL, gp, Jv, Jtv, Jx, cgls_solver, sub_pb, sub_solver, sub_stats)
end

# List of keywords accepted by PercivalSolver
Expand Down Expand Up @@ -220,6 +223,7 @@ function SolverCore.reset!(solver::PercivalSolver)
solver
end
function SolverCore.reset!(solver::PercivalSolver, model::AbstractNLPModel)
solver.Jx = jac_op!(model, solver.x, solver.Jv, solver.Jtv)
solver.sub_pb.model = model
solver.sub_pb.meta.x0 .= model.meta.x0
solver.sub_pb.meta.lvar .= model.meta.lvar
Expand Down Expand Up @@ -272,7 +276,7 @@ function SolverCore.solve!(

gp = solver.gp
gp .= zero(T)
Jx = jac_op(nlp, x)
Jx = solver.Jx
fx, gx = objgrad!(nlp, x, gx)
set_objective!(stats, fx)

Expand Down

0 comments on commit b303dbb

Please # to comment.