CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
evaluator_adcg.hpp
1 #ifndef CPPAD_CG_EVALUATOR_ADCG_INCLUDED
2 #define CPPAD_CG_EVALUATOR_ADCG_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2016 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 
24 template<class ScalarIn, class BaseOut>
25 class Evaluator<ScalarIn, CG<BaseOut>, CppAD::AD<CG<BaseOut> > > : public EvaluatorAD<ScalarIn, CG<BaseOut>, Evaluator<ScalarIn, CG<BaseOut>, CppAD::AD<CG<BaseOut> > > > {
31 public:
32  using ScalarOut = CG<BaseOut>;
35 protected:
36  using Super::evalsAtomic_;
37  using Super::atomicFunctions_;
38  using Super::handler_;
39  using Super::evalArrayCreationOperation;
40 protected:
46  bool printFor_;
55  bool adcgName_;
56 public:
57 
58  inline Evaluator(CodeHandler<ScalarIn>& handler) :
59  Super(handler),
60  printFor_(false),
61  printForPos_(0),
62  adcgName_(true) {
63  }
64 
65  inline virtual ~Evaluator() {
66  }
67 
73  inline void setPrintFor(bool printFor) {
74  printFor_ = printFor;
75  }
76 
83  inline bool isPrintFor() const {
84  return printFor_;
85  }
86 
94  inline void setPrintForPos(const ActiveOut& pos) {
95  printForPos_ = pos;
96  }
97 
105  inline const ActiveOut& getPrintForPos() const {
106  return printForPos_;
107  }
108 
113  inline void setCopyAdCgName(bool adcgName) {
114  adcgName_ = adcgName;
115  }
116 
122  inline bool isCopyAdCgName() const {
123  return adcgName_;
124  }
125 
126 protected:
127 
133  ActiveOut& a) {
134  if (node.getName() != nullptr) {
135  if(adcgName_ && CppAD::Variable(a)) {
136  ScalarOut a2(CppAD::Value(CppAD::Var2Par(a)));
137  if (a2.getOperationNode() != nullptr) {
138  a2.getOperationNode()->setName(*node.getName());
139  }
140  }
141 
142  if (printFor_) {
143  CppAD::PrintFor(printForPos_, "", a, node.getName()->c_str());
144  }
145  }
146  }
147 
148 };
149 
150 } // END cg namespace
151 } // END CppAD namespace
152 
153 #endif
void processActiveOut(const OperationNode< ScalarIn > &node, ActiveOut &a)
const std::string * getName() const