1#ifndef CPPAD_CG_LANG_C_UTIL_INCLUDED
2#define CPPAD_CG_LANG_C_UTIL_INCLUDED
28inline void printModel(ADFun<
CG<Base> >& fun) {
29 std::vector<std::string> depNames;
30 std::vector<std::string> indepNames;
31 printModel(fun, depNames, indepNames);
42inline 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())
50 std::
vector<
CG<Base> > indep0(fun.Domain());
51 handler.makeVariables(indep0);
53 std::
vector<
CG<Base> > dep0 = fun.Forward(0, indep0);
61 "y",
"x",
"z",
"array");
63 std::ostringstream code;
64 handler.generateCode(code, langC, dep0, nameGen);
65 std::cout <<
"\n" << code.str() << std::endl;
72inline
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!");
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;
96 std::ostream& out = std::cout) {