@@ -1365,19 +1365,14 @@ function get_optim_functions(
13651365 )
13661366 ∇J_prep = prepare_gradient (Jfunc!, grad_backend, Z̃_∇J, ∇J_context... ; strict)
13671367 ∇J = Vector {JNT} (undef, nZ̃)
1368- ∇Jfunc! = if nZ̃ == 1
1369- function (Z̃arg)
1370- Z̃_∇J .= Z̃arg
1371- gradient! (Jfunc!, ∇J, ∇J_prep, grad_backend, Z̃_∇J, ∇J_context... )
1372- return ∇J[begin ] # univariate syntax, see JuMP.@operator doc
1373- end
1374- else
1375- function (∇J:: AbstractVector{T} , Z̃arg:: Vararg{T, N} ) where {N, T<: Real }
1376- Z̃_∇J .= Z̃arg
1377- gradient! (Jfunc!, ∇J, ∇J_prep, grad_backend, Z̃_∇J, ∇J_context... )
1378- return ∇J # multivariate syntax, see JuMP.@operator doc
1379- end
1368+ ∇Jfunc! = function (∇J:: AbstractVector{T} , Z̃arg:: Vararg{T, N} ) where {N, T<: Real }
1369+ # only the multivariate syntax of JuMP.@operator, univariate is impossible for MHE
1370+ # since Z̃ comprises the arrival state estimate AND the estimated process noise
1371+ Z̃_∇J .= Z̃arg
1372+ gradient! (Jfunc!, ∇J, ∇J_prep, grad_backend, Z̃_∇J, ∇J_context... )
1373+ return ∇J
13801374 end
1375+
13811376 # --------------------- inequality constraint functions -------------------------------
13821377 gfuncs = Vector {Function} (undef, ng)
13831378 for i in eachindex (gfuncs)
@@ -1408,22 +1403,13 @@ function get_optim_functions(
14081403 ∇g = init_diffmat (JNT, jac_backend, ∇g_prep, nZ̃, ng)
14091404 ∇gfuncs! = Vector {Function} (undef, ng)
14101405 for i in eachindex (∇gfuncs!)
1411- ∇gfuncs![i] = if nZ̃ == 1
1412- function (Z̃arg:: T ) where T<: Real
1413- if isdifferent (Z̃arg, Z̃_∇g)
1414- Z̃_∇g .= Z̃arg
1415- jacobian! (gfunc!, g, ∇g, ∇g_prep, jac_backend, Z̃_∇g. ∇g_context... )
1416- end
1417- return ∇g[i, begin ] # univariate syntax, see JuMP.@operator doc
1418- end
1419- else
1420- function (∇g_i, Z̃arg:: Vararg{T, N} ) where {N, T<: Real }
1421- if isdifferent (Z̃arg, Z̃_∇g)
1422- Z̃_∇g .= Z̃arg
1423- jacobian! (gfunc!, g, ∇g, ∇g_prep, jac_backend, Z̃_∇g, ∇g_context... )
1424- end
1425- return ∇g_i .= @views ∇g[i, :] # multivariate syntax, see JuMP.@operator doc
1406+ ∇gfuncs![i] = function (∇g_i, Z̃arg:: Vararg{T, N} ) where {N, T<: Real }
1407+ # only the multivariate syntax of JuMP.@operator, see above for the explanation
1408+ if isdifferent (Z̃arg, Z̃_∇g)
1409+ Z̃_∇g .= Z̃arg
1410+ jacobian! (gfunc!, g, ∇g, ∇g_prep, jac_backend, Z̃_∇g, ∇g_context... )
14261411 end
1412+ return ∇g_i .= @views ∇g[i, :]
14271413 end
14281414 end
14291415 return Jfunc, ∇Jfunc!, gfuncs, ∇gfuncs!
0 commit comments