24 determineJacobianSparsity();
27 std::map<size_t, std::vector<size_t> > elements;
28 for (
size_t e = 0; e < _jacSparsity.rows.size(); e++) {
29 elements[_jacSparsity.cols[e]].push_back(_jacSparsity.rows[e]);
32 if (!_loopTapes.empty()) {
36 prepareSparseForwardOneWithLoops(elements);
43 startingJob(
"'model (forward one)'", JobTimer::SOURCE_GENERATION);
45 if (isAtomicsUsed()) {
46 generateSparseForwardOneSourcesWithAtomics(elements);
48 generateSparseForwardOneSourcesNoAtomics(elements);
55 generateGlobalDirectionalFunctionSource(FUNCTION_SPARSE_FORWARD_ONE,
57 FUNCTION_FORWARD_ONE_SPARSITY,
68 size_t n = _fun.Domain();
72 const std::string jobName =
"model (forward one)";
73 startingJob(
"'" + jobName +
"'", JobTimer::SOURCE_GENERATION);
75 for (
const auto& it : elements) {
77 const std::vector<size_t>& rows = it.second;
80 _cache <<
"model (forward one, indep " << j <<
")";
81 const std::string subJobName = _cache.str();
83 startingJob(
"'" + subJobName +
"'", JobTimer::GRAPH);
86 handler.setJobTimer(_jobTimer);
91 for (
size_t i = 0; i < n; i++) {
92 indVars[i].setValue(_x[i]);
103 _fun.Forward(0, indVars);
107 CPPADCG_ASSERT_UNKNOWN(dy.size() == _fun.Range());
110 for (
size_t it2 : rows) {
111 dyCustom.push_back(dy[it2]);
121 _cache << _name <<
"_" << FUNCTION_SPARSE_FORWARD_ONE <<
"_indep" << j;
122 langC.setGenerateFunction(_cache.str());
124 std::ostringstream code;
125 std::unique_ptr<VariableNameGenerator<Base> > nameGen(createVariableNameGenerator(
"dy"));
128 handler.
generateCode(code, langC, dyCustom, nameGenHess, _atomicFunctions, subJobName);
139 size_t n = _fun.Domain();
142 handler.setJobTimer(_jobTimer);
147 for (
size_t i = 0; i < n; i++) {
148 x[i].setValue(_x[i]);
160 CppAD::sparse_jacobian_work work;
161 _fun.SparseJacobianForward(x, _jacSparsity.sparsity, _jacSparsity.rows, _jacSparsity.cols, jacFlat, work);
166 std::map<size_t, vector<CGBase> > jac;
167 std::map<size_t, std::map<size_t, size_t> > positions;
169 for (
const auto& it : elements) {
171 const std::vector<size_t>& column = it.second;
173 jac[j].resize(column.size());
174 std::map<size_t, size_t>& pos = positions[j];
176 for (
size_t e = 0; e < column.size(); e++) {
177 size_t i = column[e];
182 for (
size_t el = 0; el < _jacSparsity.rows.size(); el++) {
183 size_t i = _jacSparsity.rows[el];
184 size_t j = _jacSparsity.cols[el];
185 size_t e = positions[j].at(i);
188 column[e] = jacFlat[el] * dx;
194 typename std::map<size_t, vector<CGBase> >::iterator itJ;
195 for (itJ = jac.begin(); itJ != jac.end(); ++itJ) {
196 size_t j = itJ->first;
200 _cache <<
"model (forward one, indep " << j <<
")";
201 const std::string subJobName = _cache.str();
208 _cache << _name <<
"_" << FUNCTION_SPARSE_FORWARD_ONE <<
"_indep" << j;
209 langC.setGenerateFunction(_cache.str());
211 std::ostringstream code;
212 std::unique_ptr<VariableNameGenerator<Base> > nameGen(createVariableNameGenerator(
"dy"));
215 handler.
generateCode(code, langC, dyCustom, nameGenHess, _atomicFunctions, subJobName);
static void printFunctionDeclaration(std::ostringstream &out, const std::string &returnType, const std::string &functionName, const std::vector< std::string > &arguments, const std::vector< std::string > &arguments2={})