Skip to content

Commit 48c9f41

Browse files
committed
Fix test expectations to match CSC lower triangular ordering
The SMC-based Hessian recovery stores nonzeros in lower triangular CSC format (column-major: all entries of column j before column j+1, with diagonal first in each column). Update all multivariate Hessian structure and value expectations to match this ordering instead of the old diagonal-first ordering. https://claude.ai/code/session_01WBu9hZukriWDSSybN9gfBq
1 parent 9ed4d93 commit 48c9f41

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

test/ReverseAD.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ function test_objective_quadratic_multivariate()
103103
g = [NaN, NaN]
104104
MOI.eval_objective_gradient(evaluator, g, [1.2, 2.3])
105105
@test g == [2 * 1.2 + 2.3, 1.2 + 2 * 2.3]
106-
@test MOI.hessian_objective_structure(evaluator) == [(1, 1), (2, 2), (2, 1)]
106+
@test MOI.hessian_objective_structure(evaluator) == [(1, 1), (2, 1), (2, 2)]
107107
H = [NaN, NaN, NaN]
108108
MOI.eval_hessian_objective(evaluator, H, [1.2, 2.3])
109-
@test H == [2.0, 2.0, 1.0]
109+
@test H == [2.0, 1.0, 2.0]
110110
@test MOI.hessian_lagrangian_structure(evaluator) ==
111-
[(1, 1), (2, 2), (2, 1)]
111+
[(1, 1), (2, 1), (2, 2)]
112112
H = [NaN, NaN, NaN]
113113
MOI.eval_hessian_lagrangian(evaluator, H, [1.2, 2.3], 1.5, Float64[])
114-
@test H == 1.5 .* [2.0, 2.0, 1.0]
114+
@test H == 1.5 .* [2.0, 1.0, 2.0]
115115
v = [0.3, 0.4]
116116
hv = [NaN, NaN]
117117
MOI.eval_hessian_lagrangian_product(
@@ -143,19 +143,19 @@ function test_objective_quadratic_multivariate_subexpressions()
143143
MOI.eval_objective_gradient(evaluator, g, val)
144144
@test g == [2 * 1.2 + 2.3, 1.2 + 2 * 2.3]
145145
@test 0 == @allocated MOI.eval_objective_gradient(evaluator, g, val)
146-
@test MOI.hessian_objective_structure(evaluator) == [(1, 1), (2, 2), (2, 1)]
146+
@test MOI.hessian_objective_structure(evaluator) == [(1, 1), (2, 1), (2, 2)]
147147
H = [NaN, NaN, NaN]
148148
MOI.eval_hessian_objective(evaluator, H, val)
149-
@test H == [2.0, 2.0, 1.0]
149+
@test H == [2.0, 1.0, 2.0]
150150
@test evaluator.backend.max_chunk == 2
151151
@test 0 == @allocated MOI.eval_hessian_objective(evaluator, H, val)
152152
@test MOI.hessian_lagrangian_structure(evaluator) ==
153-
[(1, 1), (2, 2), (2, 1)]
153+
[(1, 1), (2, 1), (2, 2)]
154154
H = [NaN, NaN, NaN]
155155
μ = Float64[]
156156
MOI.eval_hessian_lagrangian(evaluator, H, val, 1.5, μ)
157157
@test 0 == @allocated MOI.eval_hessian_lagrangian(evaluator, H, val, 1.5, μ)
158-
@test H == 1.5 .* [2.0, 2.0, 1.0]
158+
@test H == 1.5 .* [2.0, 1.0, 2.0]
159159
v = [0.3, 0.4]
160160
hv = [NaN, NaN]
161161
MOI.eval_hessian_lagrangian_product(evaluator, hv, val, v, 1.5, μ)
@@ -276,10 +276,10 @@ function test_constraint_quadratic_multivariate()
276276
MOI.eval_constraint_jacobian(evaluator, J, x_val)
277277
@test J == [2 * x_val[1] + x_val[2], x_val[1] + 2 * x_val[2]]
278278
@test MOI.hessian_lagrangian_structure(evaluator) ==
279-
[(1, 1), (2, 2), (2, 1)]
279+
[(1, 1), (2, 1), (2, 2)]
280280
H = [NaN, NaN, NaN]
281281
MOI.eval_hessian_lagrangian(evaluator, H, x_val, 0.0, [1.5])
282-
@test H == 1.5 .* [2.0, 2.0, 1.0]
282+
@test H == 1.5 .* [2.0, 1.0, 2.0]
283283
return
284284
end
285285

@@ -313,10 +313,10 @@ function test_constraint_quadratic_multivariate_subexpressions()
313313
@test y wJ[:]
314314
# Hessian-Lagrangian
315315
@test MOI.hessian_lagrangian_structure(evaluator) ==
316-
[(1, 1), (2, 2), (2, 1)]
316+
[(1, 1), (2, 1), (2, 2)]
317317
H = [NaN, NaN, NaN]
318318
MOI.eval_hessian_lagrangian(evaluator, H, x_val, 0.0, [1.5])
319-
@test H 1.5 .* [2.0, 2.0, 1.0]
319+
@test H 1.5 .* [2.0, 1.0, 2.0]
320320
return
321321
end
322322

@@ -342,10 +342,10 @@ function test_hessian_sparsity_registered_function()
342342
@test :Hess in ArrayDiff.features_available(evaluator)
343343
MOI.initialize(evaluator, [:Grad, :Jac, :Hess])
344344
@test MOI.hessian_lagrangian_structure(evaluator) ==
345-
[(1, 1), (2, 2), (3, 3), (3, 1)]
345+
[(1, 1), (3, 1), (2, 2), (3, 3)]
346346
H = fill(NaN, 4)
347347
MOI.eval_hessian_lagrangian(evaluator, H, rand(3), 1.5, Float64[])
348-
@test H == 1.5 .* [2.0, 2.0, 2.0, 0.0]
348+
@test H == 1.5 .* [2.0, 0.0, 2.0, 2.0]
349349
return
350350
end
351351

@@ -372,10 +372,10 @@ function test_hessian_sparsity_registered_rosenbrock()
372372
@test :Hess in ArrayDiff.features_available(evaluator)
373373
MOI.initialize(evaluator, [:Grad, :Jac, :Hess])
374374
@test MOI.hessian_lagrangian_structure(evaluator) ==
375-
[(1, 1), (2, 2), (2, 1)]
375+
[(1, 1), (2, 1), (2, 2)]
376376
H = fill(NaN, 3)
377377
MOI.eval_hessian_lagrangian(evaluator, H, [1.0, 1.0], 1.5, Float64[])
378-
@test H == 1.5 .* [802.0, 200.0, -400.0]
378+
@test H == 1.5 .* [802.0, -400.0, 200.0]
379379
return
380380
end
381381

0 commit comments

Comments
 (0)