174 const std::set<size_t>& iterations,
180 if (iterations.size() == iterCount) {
188 if (value.isIdenticalZero())
198 set<size_t> usedIter;
199 OperationNode<Base>* cond = loops::createIndexConditionExpressionOp<Base>(handler, iterations, usedIter, iterCount - 1, iterationIndexOp);
204 OperationNode<Base>* tmpAssign1 = handler.makeNode(CGOpCode::LoopIndexedTmp,{tmpArg, asArgument(value)});
205 OperationNode<Base>* ifAssign = handler.makeNode(CGOpCode::CondResult,{*ifStart, *tmpAssign1});
210 OperationNode<Base>* tmpAssign2 = handler.makeNode(CGOpCode::LoopIndexedTmp,{tmpArg, Base(0)});
211 OperationNode<Base>* elseAssign = handler.makeNode(CGOpCode::CondResult,{*elseStart, *tmpAssign2});
237 const std::vector<CGB>& x,
238 std::vector<CGB>& temps,
239 const VectorSet& noLoopEvalJacSparsity,
240 bool individualColoring) {
242 using namespace CppAD::cg::loops;
244 CPPADCG_ASSERT_UNKNOWN(hessSparsity_)
247 size_t m = getTapeDependentCount();
248 size_t n =
fun_->Domain();
250 std::vector<std::vector<CGB> > vwNoLoop(loopHessInfo.size());
251 std::vector<map<size_t, map<size_t, CGB> > > vhessNoLoop(loopHessInfo.size());
256 std::vector<std::set<size_t> > noLoopEvalHessTempsSparsity(n);
258 for (
const auto& itLoop2Info : loopHessInfo) {
261 addMatrixSparsity(info.noLoopEvalHessTempsSparsity, noLoopEvalHessTempsSparsity);
263 std::vector<size_t> hesRow, hesCol;
264 generateSparsityIndexes(noLoopEvalHessTempsSparsity, hesRow, hesCol);
267 for (
const auto& itLoop2Info : loopHessInfo) {
273 size_t nEqGroups = eqGroups.size();
275 std::vector<CGB>& wNoLoop = vwNoLoop[l];
277 for (
size_t inl = 0; inl < mo; inl++) {
278 wNoLoop[inl] = Base(0);
281 for (
size_t inl = mo; inl < m; inl++) {
285 if (posK !=
nullptr) {
287 for (
size_t g = 0; g < nEqGroups; g++) {
292 for (
size_t tapeI : group.
tapeI) {
293 const map<size_t, CGB>& row = info.
dyiDzk[tapeI];
294 typename map<size_t, CGB>::const_iterator itCol = row.find(posK->tape);
295 if (itCol != row.end()) {
296 const CGB& dydz = itCol->second;
297 v += dydz * info.w[tapeI];
308 *info.iterationIndexOp);
319 std::vector<map<size_t, CGB> > dyDx;
320 generateLoopForJacHes(*
fun_, x, vwNoLoop, temps,
321 getJacobianSparsity(),
322 noLoopEvalJacSparsity,
325 noLoopEvalHessTempsSparsity,
330 map<size_t, map<size_t, CGB> > dzDx;
331 for (
size_t inl = mo; inl < m; inl++) {
339 for (
auto& itLoop2Info : loopHessInfo) {
341 info.dzDxx = vhessNoLoop[l];
349 const std::vector<CGB>& w,
350 const VectorSet& noLoopEvalHessSparsity,
351 const std::vector<std::map<
size_t, std::set<size_t> > >& noLoopEvalHessLocations,
352 std::vector<CGB>& hess) {
354 using namespace CppAD::cg::loops;
356 CPPADCG_ASSERT_UNKNOWN(hessSparsity_)
358 std::vector<CGB> wNoLoop(getTapeDependentCount());
359 std::vector<CGB> hessNoLoop;
364 std::vector<size_t> row, col;
365 generateSparsityIndexes(noLoopEvalHessSparsity, row, col);
368 hessNoLoop.resize(row.size());
374 CppAD::sparse_hessian_work work;
378 work.color_method =
"cppad.general";
382 for (
size_t el = 0; el < row.size(); el++) {
385 const set<size_t>& locations = noLoopEvalHessLocations[j1].at(j2);
386 for (
size_t itE : locations)
387 hess[itE] = hessNoLoop[el];