CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
model_c_source_gen_for0.hpp
1#ifndef CPPAD_CG_MODEL_C_SOURCE_GEN_FOR0_INCLUDED
2#define CPPAD_CG_MODEL_C_SOURCE_GEN_FOR0_INCLUDED
3/* --------------------------------------------------------------------------
4 * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5 * Copyright (C) 2012 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
18namespace CppAD {
19namespace cg {
20
21template<class Base>
23 const std::string jobName = "model (zero-order forward)";
24
25 startingJob("'" + jobName + "'", JobTimer::GRAPH);
26
27 CodeHandler<Base> handler;
28 handler.setJobTimer(_jobTimer);
29
30 std::vector<CGBase> indVars(_fun.Domain());
31 handler.makeVariables(indVars);
32 if (_x.size() > 0) {
33 for (size_t i = 0; i < indVars.size(); i++) {
34 indVars[i].setValue(_x[i]);
35 }
36 }
37
38 std::vector<CGBase> dep;
39
40 if (_loopTapes.empty()) {
41 dep = _fun.Forward(0, indVars);
42 } else {
46 dep = prepareForward0WithLoops(handler, indVars);
47 }
48
49 finishedJob();
50
51 LanguageC<Base> langC(_baseTypeName);
52 langC.setMaxAssignmentsPerFunction(_maxAssignPerFunc, &_sources);
53 langC.setMaxOperationsPerAssignment(_maxOperationsPerAssignment);
54 langC.setParameterPrecision(_parameterPrecision);
55 langC.setGenerateFunction(_name + "_" + FUNCTION_FORWAD_ZERO);
56
57 std::ostringstream code;
58 std::unique_ptr<VariableNameGenerator<Base> > nameGen(createVariableNameGenerator());
59
60 handler.generateCode(code, langC, dep, *nameGen, _atomicFunctions, jobName);
61}
62
63
64} // END cg namespace
65} // END CppAD namespace
66
67#endif
void makeVariables(VectorCG &variables)
virtual void generateCode(std::ostream &out, Language< Base > &lang, CppAD::vector< CGB > &dependent, VariableNameGenerator< Base > &nameGen, const std::string &jobName="source")
virtual void setParameterPrecision(size_t p)
void setMaxOperationsPerAssignment(size_t maxOperationsPerAssignment)
virtual void setMaxAssignmentsPerFunction(size_t maxAssignmentsPerFunction, std::map< std::string, std::string > *sources)