Skip to content

Commit ac4add4

Browse files
committed
Rely on the store contract of the product callbacks
MOI.eval_constraint_jacobian_transpose_product and MOI.eval_hessian_lagrangian_product store their result, zeroing the output, so calling the inner evaluator first makes pre-filling the output redundant. The Jacobian product only zeroes the rows of the QP block, into which the block accumulates; the inner evaluator stores its own rows.
1 parent 280be1f commit ac4add4

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

src/Nonlinear/model_with_quad.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,12 @@ function MOI.eval_hessian_lagrangian(d::EvaluatorWithQuad, H, x, σ, μ)
469469
return
470470
end
471471

472-
# The rows of the two blocks are disjoint, so zero everything and let each
473-
# block write its own rows.
472+
# The rows of the two blocks are disjoint: the inner evaluator stores its
473+
# rows, and the QP block accumulates into its rows, which must be zeroed
474+
# first.
474475
function MOI.eval_constraint_jacobian_product(d::EvaluatorWithQuad, y, x, w)
475-
fill!(y, zero(eltype(y)))
476476
m = length(d.model.qp)
477+
fill!(view(y, 1:m), zero(eltype(y)))
477478
MOI.eval_constraint_jacobian_product(
478479
d.inner,
479480
view(y, (m+1):length(y)),
@@ -484,16 +485,15 @@ function MOI.eval_constraint_jacobian_product(d::EvaluatorWithQuad, y, x, w)
484485
return
485486
end
486487

487-
# Both blocks accumulate into the same variable-dimensional output. Call the
488-
# inner evaluator FIRST because implementations are allowed to overwrite the
489-
# output, and accumulate the QP block afterwards.
488+
# Both blocks contribute to the same variable-dimensional output.
489+
# `MOI.eval_constraint_jacobian_transpose_product` is called first as it
490+
# zeroes the output before accumulating, then the QP block accumulates.
490491
function MOI.eval_constraint_jacobian_transpose_product(
491492
d::EvaluatorWithQuad,
492493
y,
493494
x,
494495
w,
495496
)
496-
fill!(y, zero(eltype(y)))
497497
m = length(d.model.qp)
498498
MOI.eval_constraint_jacobian_transpose_product(
499499
d.inner,
@@ -505,6 +505,8 @@ function MOI.eval_constraint_jacobian_transpose_product(
505505
return
506506
end
507507

508+
# `MOI.eval_hessian_lagrangian_product` is called first as it zeroes the
509+
# output before accumulating, then the QP block accumulates.
508510
function MOI.eval_hessian_lagrangian_product(
509511
d::EvaluatorWithQuad,
510512
H,
@@ -513,7 +515,6 @@ function MOI.eval_hessian_lagrangian_product(
513515
σ,
514516
μ,
515517
)
516-
fill!(H, zero(eltype(H)))
517518
m = length(d.model.qp)
518519
MOI.eval_hessian_lagrangian_product(
519520
d.inner,

0 commit comments

Comments
 (0)