@@ -590,7 +590,6 @@ function get_optim_functions(
590
590
jac_backend :: AbstractADType
591
591
) where JNT<: Real
592
592
model, transcription = mpc. estim. model, mpc. transcription
593
- # TODO : initialize jacobian as sparsed if it's the case?
594
593
# TODO : fix type of all cache to ::Vector{JNT} (verify performance difference with and w/o)
595
594
# TODO : mêmes choses pour le MHE
596
595
# --------------------- update simulation function ------------------------------------
@@ -631,14 +630,14 @@ function get_optim_functions(
631
630
update_simulations! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
632
631
return obj_nonlinprog! (Ŷ0, U0, mpc, model, Ue, Ŷe, ΔŨ)
633
632
end
634
- Z̃_∇J = fill (myNaN, nZ̃)
635
- ∇J = zeros (JNT, nZ̃) # gradient of objective J
633
+ Z̃_∇J = fill (myNaN, nZ̃)
636
634
∇J_context = (
637
635
Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
638
636
Cache (Û0), Cache (X̂0),
639
637
Cache (gc), Cache (g), Cache (geq)
640
638
)
641
639
∇J_prep = prepare_gradient (Jfunc!, grad_backend, Z̃_∇J, ∇J_context... )
640
+ ∇J = Vector {JNT} (undef, nZ̃)
642
641
∇Jfunc! = if nZ̃ == 1
643
642
function (Z̃arg)
644
643
Z̃_∇J .= Z̃arg
@@ -668,7 +667,6 @@ function get_optim_functions(
668
667
return update_simulations! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
669
668
end
670
669
Z̃_∇g = fill (myNaN, nZ̃)
671
- ∇g = zeros (JNT, ng, nZ̃) # Jacobian of inequality constraints g
672
670
∇g_context = (
673
671
Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
674
672
Cache (Û0), Cache (X̂0),
@@ -679,6 +677,7 @@ function get_optim_functions(
679
677
mpc. con. i_g .= true
680
678
∇g_prep = prepare_jacobian (gfunc!, g, jac_backend, Z̃_∇g, ∇g_context... )
681
679
mpc. con. i_g .= i_g_old
680
+ ∇g = init_diffmat (JNT, jac_backend, ∇g_prep, nZ̃, ng)
682
681
∇gfuncs! = Vector {Function} (undef, ng)
683
682
for i in eachindex (∇gfuncs!)
684
683
∇gfuncs_i! = if nZ̃ == 1
@@ -716,13 +715,13 @@ function get_optim_functions(
716
715
return update_simulations! (Z̃, ΔŨ, x̂0end, Ue, Ŷe, U0, Ŷ0, Û0, X̂0, gc, g, geq)
717
716
end
718
717
Z̃_∇geq = fill (myNaN, nZ̃)
719
- ∇geq = zeros (JNT, neq, nZ̃) # Jacobian of equality constraints geq
720
718
∇geq_context = (
721
719
Cache (ΔŨ), Cache (x̂0end), Cache (Ue), Cache (Ŷe), Cache (U0), Cache (Ŷ0),
722
720
Cache (Û0), Cache (X̂0),
723
721
Cache (gc), Cache (g)
724
722
)
725
723
∇geq_prep = prepare_jacobian (geqfunc!, geq, jac_backend, Z̃_∇geq, ∇geq_context... )
724
+ ∇geq = init_diffmat (JNT, jac_backend, ∇geq_prep, nZ̃, neq)
726
725
∇geqfuncs! = Vector {Function} (undef, neq)
727
726
for i in eachindex (∇geqfuncs!)
728
727
# only multivariate syntax, univariate is impossible since nonlinear equality
0 commit comments