CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
loop_end_operation_node.hpp
1#ifndef CPPAD_CG_LOOP_END_OPERATION_NODE_INCLUDED
2#define CPPAD_CG_LOOP_END_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>
31class LoopEndOperationNode : public OperationNode<Base> {
32 friend class CodeHandler<Base>;
33public:
34
35 inline const LoopStartOperationNode<Base>& getLoopStart() const {
36 const std::vector<Argument<Base> >& args = this->getArguments();
37 CPPADCG_ASSERT_KNOWN(args.size() > 0, "There must be at least one argument")
38
39 OperationNode<Base>* aNode = args[0].getOperation();
40 CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::LoopStart, "The first argument must be the loop start operation")
41
42 return dynamic_cast<LoopStartOperationNode<Base>&> (*aNode);
43 }
44
45 inline virtual ~LoopEndOperationNode() = default;
46
47protected:
48
51 const std::vector<Argument<Base> >& endArgs) :
52 OperationNode<Base>(handler, CGOpCode::LoopEnd, std::vector<size_t>(0), createArguments(loopStart, endArgs)) {
53 }
54
55private:
56
57 static inline std::vector<Argument<Base> > createArguments(LoopStartOperationNode<Base>& lstart,
58 const std::vector<Argument<Base> >& endArgs) {
59 std::vector<Argument<Base> > args(1 + endArgs.size());
60 args[0] = lstart;
61 std::copy(endArgs.begin(), endArgs.end(), args.begin() + 1);
62 return args;
63 }
64
65};
66
67} // END cg namespace
68} // END CppAD namespace
69
70#endif
const std::vector< Argument< Base > > & getArguments() const
CGOpCode getOperationType() const