1 #ifndef CPPAD_CG_LANG_C_UTIL_INCLUDED 2 #define CPPAD_CG_LANG_C_UTIL_INCLUDED 27 inline void printModel(ADFun<CG<Base> >& fun) {
28 std::vector<std::string> depNames;
29 std::vector<std::string> indepNames;
30 printModel(fun, depNames, indepNames);
41 inline void printModel(ADFun<CG<Base> >& fun,
42 const std::vector<std::string>& depNames,
43 const std::vector<std::string>& indepNames) {
44 CPPADCG_ASSERT_UNKNOWN(depNames.size() <= fun.Range());
45 CPPADCG_ASSERT_UNKNOWN(indepNames.size() <= fun.Domain());
47 CodeHandler<Base> handler;
49 std::vector<CG<Base> > indep0(fun.Domain());
50 handler.makeVariables(indep0);
52 std::vector<CG<Base> > dep0 = fun.Forward(0, indep0);
54 LanguageC<Base> langC(
"double");
59 LangCCustomVariableNameGenerator<Base> nameGen(depNames, indepNames,
60 "y",
"x",
"z",
"array");
62 std::ostringstream code;
63 handler.generateCode(code, langC, dep0, nameGen);
64 std::cout <<
"\n" << code.str() << std::endl;
71 inline void printExpression(
const CG<Base>& dep,
72 std::ostream& out = std::cout) {
73 if(dep.getOperationNode() !=
nullptr) {
74 if(dep.getOperationNode()->getCodeHandler() ==
nullptr) {
75 throw CGException(
"Unable to print expression: found an operation node without a CodeHandler!");
78 CodeHandler<Base>& handler = *dep.getOperationNode()->getCodeHandler();
79 LanguageC<double> langC(
"double");
80 LangCDefaultVariableNameGenerator<double> nameGen;
82 std::vector<CG<Base> > depv(1);
85 std::ostringstream code;
86 handler.generateCode(code, langC, depv, nameGen);
89 out <<
"y[0] = " << dep.getValue() <<
";" << std::endl;
94 inline void printExpression(OperationNode<Base>& dep,
95 std::ostream& out = std::cout) {
96 printExpression(CG<Base>(dep), out);