1 #ifndef CPPAD_CG_LANG_C_UTIL_INCLUDED
2 #define CPPAD_CG_LANG_C_UTIL_INCLUDED
28 inline void printModel(ADFun<CG<Base> >& fun) {
29 std::vector<std::string> depNames;
30 std::vector<std::string> indepNames;
31 printModel(fun, depNames, indepNames);
42 inline void printModel(ADFun<CG<Base> >& fun,
43 const std::vector<std::string>& depNames,
44 const std::vector<std::string>& indepNames) {
45 CPPADCG_ASSERT_UNKNOWN(depNames.size() <= fun.Range())
46 CPPADCG_ASSERT_UNKNOWN(indepNames.size() <= fun.Domain())
48 CodeHandler<Base> handler;
50 std::vector<CG<Base> > indep0(fun.Domain());
51 handler.makeVariables(indep0);
53 std::vector<CG<Base> > dep0 = fun.Forward(0, indep0);
55 LanguageC<Base> langC("
double");
60 LangCCustomVariableNameGenerator<Base> nameGen(depNames, indepNames,
61 "y", "x", "z", "array");
63 std::ostringstream code;
64 handler.generateCode(code, langC, dep0, nameGen);
65 std::cout << "\n" << code.str() << std::endl;
72 inline
void printExpression(const CG<Base>& dep,
73 std::ostream& out = std::cout) {
74 if(dep.getOperationNode() !=
nullptr) {
75 if(dep.getOperationNode()->getCodeHandler() ==
nullptr) {
76 throw CGException(
"Unable to print expression: found an operation node without a CodeHandler!");
79 CodeHandler<Base>& handler = *dep.getOperationNode()->getCodeHandler();
80 LanguageC<double> langC(
"double");
81 LangCDefaultVariableNameGenerator<double> nameGen;
83 std::vector<CG<Base> > depv(1);
86 std::ostringstream code;
87 handler.generateCode(code, langC, depv, nameGen);
90 out <<
"y[0] = " << dep.getValue() <<
";" << std::endl;
95 inline void printExpression(OperationNode<Base>& dep,
96 std::ostream& out = std::cout) {
97 printExpression(CG<Base>(dep), out);