CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
model_c_source_gen_loops_jac_fr1.hpp
1 #ifndef CPPAD_CG_MODEL_C_SOURCE_GEN_LOOPS_JAC_FR1_INCLUDED
2 #define CPPAD_CG_MODEL_C_SOURCE_GEN_LOOPS_JAC_FR1_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2013 Ciengis
6  *
7  * CppADCodeGen is distributed under multiple licenses:
8  *
9  * - Eclipse Public License Version 1.0 (EPL1), and
10  * - GNU General Public License Version 3 (GPL3).
11  *
12  * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
13  * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
14  * ----------------------------------------------------------------------------
15  * Author: Joao Leal
16  */
17 
18 namespace CppAD {
19 namespace cg {
20 
21 template<class Base>
22 void ModelCSourceGen<Base>::generateSparseJacobianWithLoopsSourceFromForRev(const std::map<size_t, CompressedVectorInfo>& jacInfo,
23  size_t maxCompressedSize,
24  const std::string& localFunctionTypeName,
25  const std::string& suffix,
26  const std::string& keyName,
27  const std::map<size_t, std::set<size_t> >& nonLoopElements,
28  const std::map<LoopModel<Base>*, std::map<size_t, std::map<size_t, std::set<size_t> > > >& loopGroups,
29  void (*generateLocalFunctionName)(std::ostringstream& cache, const std::string& modelName, const LoopModel<Base>& loop, size_t g)) {
30  using namespace std;
31  using namespace CppAD::cg::loops;
32 
33  startingJob("'sparse Jacobian'", JobTimer::SOURCE_GENERATION);
34 
38  LanguageC<Base> langC(_baseTypeName);
39  string argsDcl = langC.generateDefaultFunctionArgumentsDcl();
40 
41  string model_function = _name + "_" + FUNCTION_SPARSE_JACOBIAN;
42  string localFunction = _name + "_" + localFunctionTypeName;
43  string nlSuffix = "noloop_" + suffix;
44 
45  _cache.str("");
46  _cache << "#include <stdlib.h>\n"
48 
49  generateFunctionDeclarationSource(_cache, localFunction, nlSuffix, nonLoopElements, argsDcl);
50  generateFunctionDeclarationSourceLoopForRev(_cache, langC, _name, keyName, loopGroups, generateLocalFunctionName);
51 
52  _cache << "\n";
53  printForRevUsageFunction(_cache, _baseTypeName, _name,
54  model_function, 2,
55  localFunction, suffix,
56  keyName, "it", "jac",
57  loopGroups,
58  nonLoopElements,
59  jacInfo,
60  generateLocalFunctionName,
61  _jacSparsity.rows.size(), maxCompressedSize);
62 
63  finishedJob();
64 
65  _sources[model_function + ".c"] = _cache.str();
66  _cache.str("");
67 }
68 
69 } // END cg namespace
70 } // END CppAD namespace
71 
72 #endif
STL namespace.
virtual void generateSparseJacobianWithLoopsSourceFromForRev(const std::map< size_t, CompressedVectorInfo > &jacInfo, size_t maxCompressedSize, const std::string &localFunctionTypeName, const std::string &suffix, const std::string &keyName, const std::map< size_t, std::set< size_t > > &nonLoopElements, const std::map< LoopModel< Base > *, std::map< size_t, std::map< size_t, std::set< size_t > > > > &loopGroups, void(*generateLocalFunctionName)(std::ostringstream &cache, const std::string &modelName, const LoopModel< Base > &loop, size_t g))