@@ -220,7 +220,7 @@ function OptimizationBase.instantiate_function(
220
220
if f. lag_h === nothing && cons != = nothing && lag_h == true
221
221
lag_extras = prepare_hessian (
222
222
lagrangian, soadtype, vcat (x, [one (eltype (x))], ones (eltype (x), num_cons)))
223
- lag_hess_prototype = zeros (Bool, length (x), length (x))
223
+ lag_hess_prototype = zeros (Bool, length (x) + num_cons + 1 , length (x) + num_cons + 1 )
224
224
225
225
function lag_h! (H:: AbstractMatrix , θ, σ, λ)
226
226
if σ == zero (eltype (θ))
@@ -232,13 +232,11 @@ function OptimizationBase.instantiate_function(
232
232
end
233
233
end
234
234
235
- function lag_h! (h, θ, σ, λ)
236
- H = eltype (θ).(lag_hess_prototype)
237
- hessian! (x -> lagrangian (x, σ, λ), H, soadtype, θ, lag_extras)
235
+ function lag_h! (h:: AbstractVector , θ, σ, λ)
236
+ H = hessian (lagrangian, soadtype, vcat (θ, [σ], λ), lag_extras)
238
237
k = 0
239
- rows, cols, _ = findnz (H)
240
- for (i, j) in zip (rows, cols)
241
- if i <= j
238
+ for i in 1 : length (θ)
239
+ for j in 1 : i
242
240
k += 1
243
241
h[k] = H[i, j]
244
242
end
@@ -442,7 +440,7 @@ function OptimizationBase.instantiate_function(
442
440
θ = augvars[1 : length (x)]
443
441
σ = augvars[length (x) + 1 ]
444
442
λ = augvars[(length (x) + 2 ): end ]
445
- return σ * _f (θ) + dot (λ, cons (θ))
443
+ return σ * _f (θ) + dot (λ, cons_oop (θ))
446
444
end
447
445
end
448
446
@@ -465,7 +463,8 @@ function OptimizationBase.instantiate_function(
465
463
end
466
464
467
465
if f. cons_vjp === nothing && cons_vjp == true && cons != = nothing
468
- extras_pullback = prepare_pullback (cons_oop, adtype, x)
466
+ extras_pullback = prepare_pullback (
467
+ cons_oop, adtype. dense_ad, x, ones (eltype (x), num_cons))
469
468
function cons_vjp! (J, θ, v)
470
469
pullback! (cons_oop, J, adtype. dense_ad, θ, v, extras_pullback)
471
470
end
@@ -476,7 +475,8 @@ function OptimizationBase.instantiate_function(
476
475
end
477
476
478
477
if f. cons_jvp === nothing && cons_jvp == true && cons != = nothing
479
- extras_pushforward = prepare_pushforward (cons_oop, adtype, x)
478
+ extras_pushforward = prepare_pushforward (
479
+ cons_oop, adtype. dense_ad, x, ones (eltype (x), length (x)))
480
480
function cons_jvp! (J, θ, v)
481
481
pushforward! (cons_oop, J, adtype. dense_ad, θ, v, extras_pushforward)
482
482
end
@@ -513,7 +513,7 @@ function OptimizationBase.instantiate_function(
513
513
if cons != = nothing && f. lag_h === nothing && lag_h == true
514
514
lag_extras = prepare_hessian (
515
515
lagrangian, soadtype, vcat (x, [one (eltype (x))], ones (eltype (x), num_cons)))
516
- lag_hess_prototype = lag_extras. coloring_result. S[1 : length (θ ), 1 : length (θ )]
516
+ lag_hess_prototype = lag_extras. coloring_result. S[1 : length (x ), 1 : length (x )]
517
517
lag_hess_colors = lag_extras. coloring_result. color
518
518
519
519
function lag_h! (H:: AbstractMatrix , θ, σ, λ)
0 commit comments