@@ -172,13 +172,6 @@ function TwiceDifferentiableConstraints(c!, lx::AbstractVector, ux::AbstractVect
172172 x_example = zeros (T, nx)
173173 λ_example = zeros (T, nc)
174174 ccache = zeros (T, nc)
175-
176- function sum_constraints (_x, _λ)
177- # TODO : get rid of this allocation with DI.Cache
178- ccache_righttype = zeros (promote_type (T, eltype (_x)), nc)
179- c! (ccache_righttype, _x)
180- return LinearAlgebra. dot (_λ, ccache_righttype)
181- end
182175
183176 jac_prep = DI. prepare_jacobian (c!, ccache, autodiff, x_example)
184177 con_jac! = let c! = c!, ccache = ccache, jac_prep = jac_prep, autodiff = autodiff
@@ -187,11 +180,15 @@ function TwiceDifferentiableConstraints(c!, lx::AbstractVector, ux::AbstractVect
187180 return _j
188181 end
189182 end
190-
191- hess_prep = DI. prepare_hessian (sum_constraints, autodiff, x_example, DI. Constant (λ_example))
192- con_hess! = let sum_constraints = sum_constraints, hess_prep = hess_prep, autodiff = autodiff
183+
184+ function sum_constraints (_x, _λ, _ccache)
185+ c! (_ccache, _x)
186+ return LinearAlgebra. dot (_λ, _ccache)
187+ end
188+ hess_prep = DI. prepare_hessian (sum_constraints, autodiff, x_example, DI. Constant (λ_example), DI. Cache (ccache))
189+ con_hess! = let sum_constraints = sum_constraints, hess_prep = hess_prep, autodiff = autodiff, ccache = ccache
193190 function (_h, _x, _λ)
194- DI. hessian! (sum_constraints, _h, hess_prep, autodiff, _x, DI. Constant (_λ))
191+ DI. hessian! (sum_constraints, _h, hess_prep, autodiff, _x, DI. Constant (_λ), DI . Cache (ccache) )
195192 return _h
196193 end
197194 end
0 commit comments