CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
loop_start_operation_node.hpp
1#ifndef CPPAD_CG_LOOP_START_OPERATION_NODE_INCLUDED
2#define CPPAD_CG_LOOP_START_OPERATION_NODE_INCLUDED
3/* --------------------------------------------------------------------------
4 * CppADCodeGen: C++ Algorithmic Differentiation with Source Code Generation:
5 * Copyright (C) 2013 Ciengis
6 * Copyright (C) 2020 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
19namespace CppAD {
20namespace cg {
21
30template<class Base>
32 friend class CodeHandler<Base>;
33public:
34
35 inline OperationNode<Base>& getIndex() const {
36 const std::vector<Argument<Base> >& args = this->getArguments();
37 CPPADCG_ASSERT_KNOWN(!args.empty(), "Invalid number of arguments")
38
39 OperationNode<Base>* aNode = args[0].getOperation();
40 CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::IndexDeclaration, "Invalid argument operation type")
41
42 return static_cast<OperationNode<Base>&> (*aNode);
43 }
44
45 inline IndexOperationNode<Base>* getIterationCountNode() const {
46 if (this->getInfo().empty()) {
47 CPPADCG_ASSERT_KNOWN(this->getArguments().size() > 1, "Invalid number of arguments.")
48
49 OperationNode<Base>* aNode = this->getArguments()[1].getOperation();
50 CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::Index, "Invalid argument node type")
51
52 return static_cast<IndexOperationNode<Base>*> (aNode);
53 }
54
55 return nullptr;
56 }
57
58 inline const size_t getIterationCount() const {
59 if (this->getInfo().empty()) {
60 return 0;
61 }
62 return this->getInfo()[0];
63 }
64
65 inline virtual ~LoopStartOperationNode() = default;
66
67protected:
68
70 OperationNode<Base>& indexDcl,
71 size_t iterationCount) :
72 OperationNode<Base>(handler, CGOpCode::LoopStart, indexDcl) {
73 this->getInfo().push_back(iterationCount);
74 }
75
77 OperationNode<Base>& indexDcl,
78 IndexOperationNode<Base>& iterCount) :
79 OperationNode<Base>(handler, CGOpCode::LoopStart,{indexDcl, iterCount}) {
80 }
81
82};
83
84} // END cg namespace
85} // END CppAD namespace
86
87#endif
const std::vector< size_t > & getInfo() const
const std::vector< Argument< Base > > & getArguments() const
CGOpCode getOperationType() const