CppADCodeGen  HEAD
A C++ Algorithmic Differentiation Package with Source Code Generation
declare_cg_loops.hpp
1 #ifndef CPPAD_CG_DECLARE_CG_LOOPS_INCLUDED
2 #define CPPAD_CG_DECLARE_CG_LOOPS_INCLUDED
3 /* --------------------------------------------------------------------------
4  * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5  * Copyright (C) 2013 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 // forward declarations
19 namespace CppAD {
20 namespace cg {
21 
22 template<class Base>
23 class vector;
24 
25 namespace loops {
26 
27 using SizeN1stIt = std::pair<size_t, size_t>;
28 
29 using pairss = std::pair<size_t, size_t>;
30 
31 class JacobianWithLoopsRowInfo;
32 
33 class HessianElement;
34 
35 template<class Base>
37 
38 template<class Base>
40 
41 template <class Base>
42 class IfElseInfo;
43 
44 template<class Base>
46 
47 template<class Base>
49 
50 template<class Base>
52 
53 template<class Base>
55 
56 template<class Base>
58 
59 class ArrayGroup;
60 
61 template<class Base>
62 inline std::vector<CG<Base> > createIndexedIndependents(CodeHandler<Base>& handler,
63  LoopModel<Base>& loop,
64  IndexOperationNode<Base>& iterationIndexOp);
65 
66 template<class Base>
67 inline std::vector<CG<Base> > createLoopIndependentVector(CodeHandler<Base>& handler,
68  LoopModel<Base>& loop,
69  const std::vector<CG<Base> >& indexedIndeps,
70  const std::vector<CG<Base> >& nonIndexedIndeps,
71  const std::vector<CG<Base> >& nonIndexedTmps);
72 
73 template<class Base>
74 inline std::vector<CG<Base> > createLoopDependentVector(CodeHandler<Base>& handler,
75  LoopModel<Base>& loop,
76  IndexOperationNode<Base>& iterationIndexOp);
77 
78 template<class Base>
79 inline CG<Base> createLoopDependentFunctionResult(CodeHandler<Base>& handler,
80  size_t i, const CG<Base>& val, IndexPattern* ip,
81  IndexOperationNode<Base>& iterationIndexOp);
82 
83 template<class Base>
84 inline LoopEndOperationNode<Base>* createLoopEnd(CodeHandler<Base>& handler,
86  const std::vector<std::pair<CG<Base>, IndexPattern*> >& indexedLoopResults,
87  const std::set<IndexOperationNode<Base>*>& indexesOps,
88  size_t assignOrAdd);
89 
90 template<class Base>
91 inline void moveNonIndexedOutsideLoop(LoopStartOperationNode<Base>& loopStart,
93 
94 template<class Base>
95 inline bool findNonIndexedNodes(OperationNode<Base>& node,
96  std::set<OperationNode<Base>*>& nonIndexed,
97  const OperationNode<Base>& loopIndex);
98 
99 template<class Base>
100 inline IfElseInfo<Base>* findExistingIfElse(std::vector<IfElseInfo<Base> >& ifElses,
101  const std::map<SizeN1stIt, std::pair<size_t, std::set<size_t> > >& first2Iterations);
102 
103 inline std::vector<size_t> createIndexConditionExpression(const std::set<size_t>& iterations,
104  const std::set<size_t>& usedIter,
105  size_t maxIter);
106 
107 template<class Base>
108 inline OperationNode<Base>* createIndexConditionExpressionOp(CodeHandler<Base>& handler,
109  const std::set<size_t>& iterations,
110  const std::set<size_t>& usedIter,
111  size_t maxIter,
112  IndexOperationNode<Base>& iterationIndexOp);
113 
114 template<class Base>
115 inline void determineForRevUsagePatterns(const std::map<LoopModel<Base>*, std::map<size_t, std::map<size_t, std::set<size_t> > > >& loopGroups,
116  const std::map<size_t, std::vector<std::set<size_t> > >& userElLocation,
117  const std::map<size_t, bool>& ordered,
118  std::map<size_t, std::map<LoopModel<Base>*, std::map<size_t, ArrayGroup*> > >& loopCalls,
120 
121 template<class Base>
122 void generateFunctionDeclarationSourceLoopForRev(std::ostringstream& cache,
123  LanguageC<Base>& langC,
124  const std::string& modelName,
125  const std::string& keyName,
126  const std::map<LoopModel<Base>*, std::map<size_t, std::map<size_t, std::set<size_t> > > >& _loopRev2Groups,
127  void (*generateFunctionNameLoopRev2)(std::ostringstream& cache, const std::string& modelName, const LoopModel<Base>& loop, size_t g));
128 
129 template<class Base>
130 inline void generateLoopForJacHes(ADFun<CG<Base> >& fun,
131  const std::vector<CG<Base> >& x,
132  const std::vector<std::vector<CG<Base> > >& vw,
133  std::vector<CG<Base> >& y,
134  const std::vector<std::set<size_t> >& jacSparsity,
135  const std::vector<std::set<size_t> >& jacEvalSparsity,
136  std::vector<std::map<size_t, CG<Base> > >& jac,
137  const std::vector<std::set<size_t> >& hesSparsity,
138  const std::vector<std::set<size_t> >& hesEvalSparsity,
139  std::vector<std::map<size_t, std::map<size_t, CG<Base> > > >& vhess,
140  bool constainsAtomics);
141 
142 } // END loops namespace
143 
144 } // END cg namespace
145 } // END CppAD namespace
146 
147 #endif