CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
index_operation_node.hpp
1#ifndef CPPAD_CG_INDEX_OPERATION_NODE_INCLUDED
2#define CPPAD_CG_INDEX_OPERATION_NODE_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
18namespace CppAD {
19namespace cg {
20
29template<class Base>
30class IndexOperationNode : public OperationNode<Base> {
31 friend class CodeHandler<Base>;
32public:
33
34 inline bool isDefinedLocally() const {
35 return this->getArguments().size() > 1;
36 }
37
38 inline OperationNode<Base>& getIndexCreationNode() const {
39 const std::vector<Argument<Base> >& args = this->getArguments();
40 CPPADCG_ASSERT_KNOWN(!args.empty(), "Invalid number of arguments");
41 CPPADCG_ASSERT_KNOWN(args.back().getOperation() != nullptr, "Invalid argument type");
42 return *args.back().getOperation();
43 }
44
45 inline const OperationNode<Base>& getIndex() const {
46 const std::vector<Argument<Base> >& args = this->getArguments();
47 CPPADCG_ASSERT_KNOWN(!args.empty(), "Invalid number of arguments");
48
49 OperationNode<Base>* aNode = args[0].getOperation();
50 CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::IndexDeclaration, "Invalid argument operation type");
51
52 return static_cast<const OperationNode<Base>&> (*aNode);
53 }
54
55 inline void makeAssigmentDependent(IndexAssignOperationNode<Base>& indexAssign) {
56 std::vector<Argument<Base> >& args = this->getArguments();
57
58 args.resize(2);
59 args[0] = indexAssign.getIndex();
60 args[1] = indexAssign;
61 }
62
63 inline virtual ~IndexOperationNode() {
64 }
65
66protected:
67
69 OperationNode<Base>& indexDcl) :
70 OperationNode<Base>(handler, CGOpCode::Index, indexDcl) {
71 }
72
75 OperationNode<Base>(handler, CGOpCode::Index,{loopStart.getIndex(), loopStart}) {
76 }
77
79 IndexAssignOperationNode<Base>& indexAssign) :
80 OperationNode<Base>(handler, CGOpCode::Index,{indexAssign.getIndex(), indexAssign}) {
81 }
82
83};
84
85} // END cg namespace
86} // END CppAD namespace
87
88#endif
const std::vector< Argument< Base > > & getArguments() const
CGOpCode getOperationType() const