@@ -163,13 +163,6 @@ function TwiceDifferentiableConstraints(c!, lx::AbstractVector, ux::AbstractVect
163163 x_example = zeros (T, nx)
164164 λ_example = zeros (T, nc)
165165 ccache = zeros (T, nc)
166-
167- function sum_constraints (_x, _λ)
168- # TODO : get rid of this allocation with DI.Cache
169- ccache_righttype = zeros (promote_type (T, eltype (_x)), nc)
170- c! (ccache_righttype, _x)
171- return sum (_λ[i] * ccache[i] for i in eachindex (_λ, ccache))
172- end
173166
174167 jac_prep = DI. prepare_jacobian (c!, ccache, autodiff, x_example)
175168 con_jac! = let c! = c!, ccache = ccache, jac_prep = jac_prep, autodiff = autodiff
@@ -178,11 +171,15 @@ function TwiceDifferentiableConstraints(c!, lx::AbstractVector, ux::AbstractVect
178171 return _j
179172 end
180173 end
181-
182- hess_prep = DI. prepare_hessian (sum_constraints, autodiff, x_example, DI. Constant (λ_example))
183- con_hess! = let sum_constraints = sum_constraints, hess_prep = hess_prep, autodiff = autodiff
174+
175+ function sum_constraints (_x, _λ, _ccache)
176+ c! (_ccache, _x)
177+ return LinearAlgebra. dot (_λ, _ccache)
178+ end
179+ hess_prep = DI. prepare_hessian (sum_constraints, autodiff, x_example, DI. Constant (λ_example), DI. Cache (ccache))
180+ con_hess! = let sum_constraints = sum_constraints, hess_prep = hess_prep, autodiff = autodiff, ccache = ccache
184181 function (_h, _x, _λ)
185- DI. hessian! (sum_constraints, _h, hess_prep, autodiff, _x, DI. Constant (_λ))
182+ DI. hessian! (sum_constraints, _h, hess_prep, autodiff, _x, DI. Constant (_λ), DI . Cache (ccache) )
186183 return _h
187184 end
188185 end
0 commit comments