CppADCodeGen 2.4.3
A C++ Algorithmic Differentiation Package with Source Code Generation
Loading...
Searching...
No Matches
index_assign_operation_node.hpp
1#ifndef CPPAD_CG_INDEX_ASSIGN_OPERATION_NODE_INCLUDED
2#define CPPAD_CG_INDEX_ASSIGN_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>
31 friend class CodeHandler<Base>;
32private:
33 IndexPattern& indexPattern_;
34public:
35
36 inline OperationNode<Base>& getIndex() const {
37 const std::vector<Argument<Base> >& args = this->getArguments();
38 CPPADCG_ASSERT_KNOWN(!args.empty(), "Invalid number of arguments");
39
40 OperationNode<Base>* aNode = args[0].getOperation();
41 CPPADCG_ASSERT_KNOWN(aNode != nullptr && aNode->getOperationType() == CGOpCode::IndexDeclaration, "Invalid argument operation type");
42
43 return static_cast<OperationNode<Base>&> (*aNode);
44 }
45
46 inline const IndexPattern& getIndexPattern() const {
47 return indexPattern_;
48 }
49
50 inline IndexPattern& getIndexPattern() {
51 return indexPattern_;
52 }
53
54 inline std::vector<const OperationNode<Base>*> getIndexPatternIndexes() const {
55 std::vector<const OperationNode<Base>*> iargs;
56
57 const std::vector<Argument<Base> >& args = this->getArguments();
58
59 CPPADCG_ASSERT_KNOWN(args[1].getOperation() != nullptr &&
60 args[1].getOperation()->getOperationType() == CGOpCode::Index, "Invalid argument operation type");
61 iargs.push_back(&static_cast<IndexOperationNode<Base>*> (args[1].getOperation())->getIndex());
62
63 if (args.size() > 2) {
64 CPPADCG_ASSERT_KNOWN(args[2].getOperation() != nullptr &&
65 args[2].getOperation()->getOperationType() == CGOpCode::Index, "Invalid argument operation type");
66 iargs.push_back(&static_cast<IndexOperationNode<Base>*> (args[2].getOperation())->getIndex());
67 }
68
69 return iargs;
70 }
71
72 inline virtual ~IndexAssignOperationNode() {
73 }
74
75protected:
76
85 IndexPattern& indexPattern,
87 OperationNode<Base>(handler, CGOpCode::IndexAssign,{index, index1}),
88 indexPattern_(indexPattern) {
89 }
90
91 inline IndexAssignOperationNode(CodeHandler<Base>* handler,
92 OperationNode<Base>& index,
93 IndexPattern& indexPattern,
94 IndexOperationNode<Base>* index1,
95 IndexOperationNode<Base>* index2) :
96 OperationNode<Base>(handler, CGOpCode::IndexAssign, std::vector<size_t> (0), createArguments(index, index1, index2)),
97 indexPattern_(indexPattern) {
98 }
99
100 inline static std::vector<Argument<Base> > createArguments(OperationNode<Base>& index,
101 IndexOperationNode<Base>* index1,
102 IndexOperationNode<Base>* index2) {
103 std::vector<Argument<Base> > args(1 + (index1 != nullptr)+ (index2 != nullptr));
104
105 args[0] = index;
106 if (index1 != nullptr)
107 args[1] = *index1;
108 if (index2 != nullptr) {
109 args.back() = *index2;
110 }
111
112 return args;
113 }
114
115};
116
117} // END cg namespace
118} // END CppAD namespace
119
120#endif
IndexAssignOperationNode(CodeHandler< Base > *handler, OperationNode< Base > &index, IndexPattern &indexPattern, IndexOperationNode< Base > &index1)
const std::vector< Argument< Base > > & getArguments() const
CGOpCode getOperationType() const