CppADCodeGen  2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
language.hpp
1 #ifndef CPPAD_CG_LANGUAGE_INCLUDED
2 #define CPPAD_CG_LANGUAGE_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2012 Ciengis
6  * Copyright (C) 2019 Joao Leal
7  *
8  * CppADCodeGen is distributed under multiple licenses:
9  *
10  * - Eclipse Public License Version 1.0 (EPL1), and
11  * - GNU General Public License Version 3 (GPL3).
12  *
13  * EPL1 terms and conditions can be found in the file "epl-v10.txt", while
14  * terms and conditions for the GPL3 can be found in the file "gpl3.txt".
15  * ----------------------------------------------------------------------------
16  * Author: Joao Leal
17  */
18 
19 namespace CppAD {
20 namespace cg {
21 
27 template<class Base>
29 public:
30  using Node = OperationNode<Base>;
31  using ScopeIDType = typename CodeHandler<Base>::ScopeIDType;
32 public:
36  const std::vector<Node *>& independent;
53  const std::vector<Node*>& variableOrder;
57  const std::vector<std::set<Node*>>& variableDependencies;
65  const std::map<size_t, size_t>& atomicFunctionId2Index;
69  const std::map<size_t, std::string>& atomicFunctionId2Name;
74  const std::vector<int>& atomicFunctionsMaxForward;
79  const std::vector<int>& atomicFunctionsMaxReverse;
83  const bool reuseIDs;
84  //
85  const std::set<const Node*>& indexes;
86  //
87  const std::set<RandomIndexPattern*>& indexRandomPatterns;
88  //
89  const std::vector<IndexPattern*>& loopDependentIndexPatterns;
90  //
91  const std::vector<IndexPattern*>& loopIndependentIndexPatterns;
108  const bool zeroDependents;
109 public:
110 
111  LanguageGenerationData(const std::vector<Node *>& ind,
112  const ArrayView<CG<Base> >& dep,
113  size_t minTempVID,
114  const CodeHandlerVector<Base, size_t>& varIds,
115  const std::vector<Node*>& vo,
116  const std::vector<std::set<Node*>>& variableDependencies,
118  const std::map<size_t, size_t>& atomicId2Index,
119  const std::map<size_t, std::string>& atomicId2Name,
120  const std::vector<int>& atomicMaxForward,
121  const std::vector<int>& atomicMaxReverse,
122  const bool ri,
123  const std::set<const Node*>& indexes,
124  const std::set<RandomIndexPattern*>& idxRandomPatterns,
125  const std::vector<IndexPattern*>& dependentIndexPatterns,
126  const std::vector<IndexPattern*>& independentIndexPatterns,
130  bool zero) :
131  independent(ind),
132  dependent(dep),
133  minTemporaryVarID(minTempVID),
134  varId(varIds),
135  variableOrder(vo),
137  nameGen(ng),
138  atomicFunctionId2Index(atomicId2Index),
139  atomicFunctionId2Name(atomicId2Name),
140  atomicFunctionsMaxForward(atomicMaxForward),
141  atomicFunctionsMaxReverse(atomicMaxReverse),
142  reuseIDs(ri),
143  indexes(indexes),
144  indexRandomPatterns(idxRandomPatterns),
145  loopDependentIndexPatterns(dependentIndexPatterns),
146  loopIndependentIndexPatterns(independentIndexPatterns),
148  scope(scope),
150  zeroDependents(zero) {
151  }
152 };
153 
159 template<class Base>
160 class Language {
161  friend class CodeHandler<Base>;
162 public:
163  using Node = OperationNode<Base>;
164 protected:
165  virtual void generateSourceCode(std::ostream& out,
166  std::unique_ptr<LanguageGenerationData<Base> > info) = 0;
167 
176  virtual bool createsNewVariable(const Node& op,
177  size_t totalUseCount,
178  size_t opCount) const = 0;
179 
180  virtual bool requiresVariableArgument(enum CGOpCode op,
181  size_t argIndex) const = 0;
182 
187  virtual bool requiresVariableDependencies() const = 0;
188 
189 };
190 
191 } // END cg namespace
192 } // END CppAD namespace
193 
194 #endif
CppAD::cg::LanguageGenerationData::variableDependencies
const std::vector< std::set< Node * > > & variableDependencies
Definition: language.hpp:57
CppAD::cg::VariableNameGenerator
Definition: declare_cg.hpp:129
CppAD::cg::LanguageGenerationData::atomicFunctionId2Index
const std::map< size_t, size_t > & atomicFunctionId2Index
Definition: language.hpp:65
CppAD::cg::LanguageGenerationData
Definition: language.hpp:28
CppAD::cg::IndexOperationNode
Definition: declare_cg.hpp:81
CppAD::cg::Language
Definition: language.hpp:160
CppAD::cg::LanguageGenerationData::atomicFunctionsMaxReverse
const std::vector< int > & atomicFunctionsMaxReverse
Definition: language.hpp:79
CppAD::cg::LanguageGenerationData::auxIterationIndexOp
IndexOperationNode< Base > & auxIterationIndexOp
Definition: language.hpp:103
CppAD::cg::LanguageGenerationData::totalUseCount
const CodeHandlerVector< Base, size_t > & totalUseCount
Definition: language.hpp:95
CppAD::cg::LanguageGenerationData::atomicFunctionsMaxForward
const std::vector< int > & atomicFunctionsMaxForward
Definition: language.hpp:74
CppAD
Definition: abstract_atomic_fun.hpp:19
CppAD::cg::Language::createsNewVariable
virtual bool createsNewVariable(const Node &op, size_t totalUseCount, size_t opCount) const =0
CppAD::cg::LanguageGenerationData::dependent
const ArrayView< CG< Base > > & dependent
Definition: language.hpp:40
CppAD::cg::LanguageGenerationData::reuseIDs
const bool reuseIDs
Definition: language.hpp:83
CppAD::cg::CG
Definition: cg.hpp:29
CppAD::cg::LanguageGenerationData::variableOrder
const std::vector< Node * > & variableOrder
Definition: language.hpp:53
CppAD::cg::CodeHandler
Definition: code_handler.hpp:28
CppAD::cg::ArrayView
Definition: array_view.hpp:30
CppAD::cg::CodeHandlerVector< Base, size_t >
CppAD::cg::LanguageGenerationData::atomicFunctionId2Name
const std::map< size_t, std::string > & atomicFunctionId2Name
Definition: language.hpp:69
CppAD::cg::LanguageGenerationData::zeroDependents
const bool zeroDependents
Definition: language.hpp:108
CppAD::cg::LanguageGenerationData::scope
const CodeHandlerVector< Base, ScopeIDType > & scope
Definition: language.hpp:99
CppAD::cg::LanguageGenerationData::varId
const CodeHandlerVector< Base, size_t > & varId
Definition: language.hpp:49
CppAD::cg::LanguageGenerationData::independent
const std::vector< Node * > & independent
Definition: language.hpp:36
CppAD::cg::OperationNode
Definition: argument.hpp:22
CppAD::cg::Language::requiresVariableDependencies
virtual bool requiresVariableDependencies() const =0
CppAD::cg::LanguageGenerationData::nameGen
VariableNameGenerator< Base > & nameGen
Definition: language.hpp:61
CppAD::cg::LanguageGenerationData::minTemporaryVarID
size_t minTemporaryVarID
Definition: language.hpp:44