CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
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
19namespace CppAD {
20namespace cg {
21
22template<class Base>
23class vector;
24
25namespace loops {
26
27using SizeN1stIt = std::pair<size_t, size_t>;
28
29using pairss = std::pair<size_t, size_t>;
30
31class JacobianWithLoopsRowInfo;
32
33class HessianElement;
34
35template<class Base>
36class LoopNonIndexedLocator;
37
38template<class Base>
39class IfBranchInfo;
40
41template <class Base>
42class IfElseInfo;
43
44template<class Base>
45class JacobianTermContrib;
46
47template<class Base>
48class JacobianColGroup;
49
50template<class Base>
51class HessianWithLoopsInfo;
52
53template<class Base>
54class HessianWithLoopsEquationGroupInfo;
55
56template<class Base>
57class HessianRowGroup;
58
59class ArrayGroup;
60
61template<class Base>
62inline std::vector<CG<Base> > createIndexedIndependents(CodeHandler<Base>& handler,
63 LoopModel<Base>& loop,
64 IndexOperationNode<Base>& iterationIndexOp);
65
66template<class Base>
67inline 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
73template<class Base>
74inline std::vector<CG<Base> > createLoopDependentVector(CodeHandler<Base>& handler,
75 LoopModel<Base>& loop,
76 IndexOperationNode<Base>& iterationIndexOp);
77
78template<class Base>
79inline CG<Base> createLoopDependentFunctionResult(CodeHandler<Base>& handler,
80 size_t i, const CG<Base>& val, IndexPattern* ip,
81 IndexOperationNode<Base>& iterationIndexOp);
82
83template<class Base>
84inline 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
90template<class Base>
91inline void moveNonIndexedOutsideLoop(LoopStartOperationNode<Base>& loopStart,
93
94template<class Base>
95inline bool findNonIndexedNodes(OperationNode<Base>& node,
96 std::set<OperationNode<Base>*>& nonIndexed,
97 const OperationNode<Base>& loopIndex);
98
99template<class Base>
100inline IfElseInfo<Base>* findExistingIfElse(std::vector<IfElseInfo<Base> >& ifElses,
101 const std::map<SizeN1stIt, std::pair<size_t, std::set<size_t> > >& first2Iterations);
102
103inline std::vector<size_t> createIndexConditionExpression(const std::set<size_t>& iterations,
104 const std::set<size_t>& usedIter,
105 size_t maxIter);
106
107template<class Base>
108inline 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
114template<class Base>
115inline 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
121template<class Base>
122void 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
129template<class Base>
130inline 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