28 using namespace CppAD::cg::loops;
31 size_t n = _fun.Domain();
35 handler.setZeroDependents(
false);
44 std::vector<OperationNode<Base>*>
localNodes(6);
52 size_t nonIndexdedEqSize = _funNoLoops !=
nullptr ? _funNoLoops->getOrigDependentIndexes().size() : 0;
57 map<LoopModel<Base>*, std::vector<JacobianWithLoopsRowInfo> >
loopEqInfo;
59 size_t nnz = _jacSparsity.rows.size();
60 std::vector<size_t> rows(nnz);
61 std::vector<size_t> cols(nnz);
62 std::vector<size_t> locations(nnz);
65 for (
const pair<
size_t, std::vector<size_t> >&
itJ : elements) {
67 const std::vector<size_t>&
r =
itJ.second;
69 for (
size_t e = 0;
e <
r.size();
e++) {
76 CPPADCG_ASSERT_UNKNOWN(
p == nnz);
78 analyseSparseJacobianWithLoops(rows, cols, locations,
81 std::vector<CGBase> x(
n);
84 for (
size_t i = 0;
i <
n;
i++) {
92 dx.setValue(Base(1.0));
103 std::vector<CGBase>
tmps;
106 map<size_t, map<size_t, CGBase> >
dzDx;
111 if (_funNoLoops !=
nullptr) {
117 std::vector<CGBase>
depNL = _funNoLoops->getTape().Forward(0, x);
120 for (
size_t i = 0;
i <
tmps.size();
i++)
127 map<size_t, map<size_t, CGBase> >
dydxT = generateLoopFor1Jac(
fun,
128 _funNoLoops->getJacobianSparsity(),
132 map<size_t, std::vector<CGBase> >
jacNl;
133 for (
const pair<
size_t, map<size_t, CGBase> >&
itDydxT :
dydxT) {
138 std::vector<CGBase>& col =
jacNl[
j];
139 col.resize(elements.at(
j).size());
141 for (
const pair<size_t, CGBase>&
itiv :
dydxjT) {
148 CPPADCG_ASSERT_UNKNOWN(locations.size() == 1);
149 size_t e = *locations.begin();
153 _nonLoopFor1Elements[
j].insert(
e);
166 typename map<size_t, std::vector<CGBase> >::iterator
itJ;
168 size_t j =
itJ->first;
169 if (_nonLoopFor1Elements.find(
j) != _nonLoopFor1Elements.end())
170 createForwardOneWithLoopsNL(
handler,
j,
itJ->second);
177 typename map<LoopModel<Base>*, std::vector<JacobianWithLoopsRowInfo> >::iterator
itl2Eq;
180 const std::vector<JacobianWithLoopsRowInfo>&
info =
itl2Eq->second;
187 _cache <<
"model (forward one, loop " <<
lModel.getLoopId() <<
")";
188 std::string
jobName = _cache.str();
193 startingJob(
"'" +
jobName +
"'", JobTimer::GRAPH);
199 map<size_t, map<size_t, CGBase> >
dyiDxtapeT = generateLoopFor1Jac(
fun,
200 lModel.getJacobianSparsity(),
227 for (
const pair<
size_t, set<size_t> >&
itJcol2It : group.jCol2Iterations) {
244 for (
const pair<
size_t, set<size_t> >&
itJcol2It : group.jCol2Iterations) {
249 set<size_t>::const_iterator
itIt;
277 for (
const pair<
size_t, set<size_t> >&
itJcol2Its : group.jCol2Iterations) {
285 size_t itCount = group.jCol2Iterations.begin()->second.size();
304 group, iterationIndexOp,
324 moveNonIndexedOutsideLoop(
handler, *loopStart, *loopEnd);
349 langC.setParameterPrecision(_parameterPrecision);
352 std::ostringstream
code;
353 std::unique_ptr<VariableNameGenerator<Base> > nameGen(createVariableNameGenerator(
"dy"));
360 _cache <<
"model (forward one, loop " <<
lModel.getLoopId() <<
", group " <<
g <<
")";
365 generateFunctionNameLoopFor1(_cache,
lModel,
g);
368 std::string
argsDcl =
langC.generateFunctionArgumentsDcl();
371 _cache <<
"#include <stdlib.h>\n"
372 "#include <math.h>\n"
377 nameGenHess.customFunctionVariableDeclarations(_cache);
378 _cache <<
langC.generateIndependentVariableDeclaration() <<
"\n";
379 _cache <<
langC.generateDependentVariableDeclaration() <<
"\n";
380 _cache <<
langC.generateTemporaryVariableDeclaration(
false,
false,
381 handler.getExternalFuncMaxForwardOrder(),
382 handler.getExternalFuncMaxReverseOrder()) <<
"\n";
383 nameGenHess.prepareCustomFunctionVariables(_cache);
386 _cache <<
code.str();
388 nameGenHess.finalizeCustomFunctionVariables(_cache);
407 string functionFor1 = _name +
"_" + FUNCTION_SPARSE_FORWARD_ONE;
408 _sources[
functionFor1 +
".c"] = generateGlobalForRevWithLoopsFunctionSource(elements,
409 _loopFor1Groups, _nonLoopFor1Elements,
411 generateFunctionNameLoopFor1);
416 generateSparsity1DSource2(_name +
"_" + FUNCTION_FORWARD_ONE_SPARSITY, elements);
417 _sources[_name +
"_" + FUNCTION_FORWARD_ONE_SPARSITY +
".c"] = _cache.str();