1#ifndef CPPAD_CG_EXPRESSION_NODE_INCLUDED
2#define CPPAD_CG_EXPRESSION_NODE_INCLUDED
31 using iterator =
typename std::vector<Argument<Base> >::iterator;
32 using const_iterator =
typename std::vector<Argument<Base> >::const_iterator;
33 using const_reverse_iterator =
typename std::vector<Argument<Base> >::const_reverse_iterator;
34 using reverse_iterator =
typename std::vector<Argument<Base> >::reverse_iterator;
36 static const std::set<CGOpCode> CUSTOM_NODE_CLASS;
50 std::vector<size_t> info_;
56 std::vector<Argument<Base> > arguments_;
64 std::unique_ptr<std::string> name_;
71 CPPADCG_ASSERT_UNKNOWN(CUSTOM_NODE_CLASS.find(operation_) == CUSTOM_NODE_CLASS.end());
73 operation_ = CGOpCode::Alias;
75 arguments_[0] =
other;
106 CPPADCG_ASSERT_UNKNOWN(
op == operation_ || CUSTOM_NODE_CLASS.find(
op) == CUSTOM_NODE_CLASS.end());
109 arguments_ = arguments;
134 inline const std::vector<size_t>&
getInfo()
const {
159 inline void setName(
const std::string& name) {
160 if (name_ !=
nullptr)
163 name_.reset(
new std::string(name));
187 inline iterator begin() {
188 return arguments_.begin();
191 inline const_iterator begin()
const {
192 return arguments_.begin();
195 inline iterator end() {
196 return arguments_.end();
199 inline const_iterator end()
const {
200 return arguments_.end();
203 inline reverse_iterator rbegin() {
204 return arguments_.rbegin();
207 inline const_reverse_iterator rbegin()
const {
208 return arguments_.rbegin();
211 inline reverse_iterator rend() {
212 return arguments_.rend();
215 inline const_reverse_iterator rend()
const {
216 return arguments_.rend();
220 return arguments_.cbegin();
224 return arguments_.cend();
228 return arguments_.crbegin();
232 return arguments_.crend();
235 inline virtual ~OperationNode() =
default;
239 inline OperationNode(
const OperationNode&
orig) :
240 handler_(
orig.handler_),
241 operation_(
orig.operation_),
243 arguments_(
orig.arguments_),
248 inline OperationNode(CodeHandler<Base>*
handler,
255 inline OperationNode(CodeHandler<Base>*
handler,
264 inline OperationNode(CodeHandler<Base>*
handler,
273 inline OperationNode(CodeHandler<Base>*
handler,
275 std::vector<size_t>&&
info,
284 inline OperationNode(CodeHandler<Base>*
handler,
286 const std::vector<size_t>&
info,
295 inline void setHandlerPosition(
size_t pos) {
307 const std::vector<size_t>&
info,
313 static inline std::set<CGOpCode> makeCustomNodeClassesSet()
noexcept;
319 std::set<CGOpCode> s;
320 s.insert(CGOpCode::IndexAssign);
321 s.insert(CGOpCode::Index);
322 s.insert(CGOpCode::LoopStart);
323 s.insert(CGOpCode::LoopEnd);
324 s.insert(CGOpCode::Pri);
329const std::set<CGOpCode> OperationNode<Base>::CUSTOM_NODE_CLASS = makeCustomNodeClassesSet();
332inline std::ostream& operator<<(
335 CGOpCode
op =
c.getOperationType();
337 case CGOpCode::ArrayCreation:
338 os <<
"new $1[" <<
c.getArguments().size() <<
"]";
340 case CGOpCode::SparseArrayCreation:
341 os <<
"new $1[" <<
c.getInfo()[0] <<
"]";
343 case CGOpCode::ArrayElement:
344 os <<
"$1[" <<
c.getInfo()[0] <<
"]";
346 case CGOpCode::AtomicForward:
347 os <<
"atomicFunction.forward(" <<
c.getInfo()[0] <<
", " <<
c.getInfo()[1] <<
", vx, vy, $1, $2)";
349 case CGOpCode::AtomicReverse:
350 os <<
"atomicFunction.reverse(" <<
c.getInfo()[0] <<
", $1, $2, $3, $4)";
353 os <<
"if($1 > 0) { 1 } else if($1 == 0) { 0 } else { -1 }";
void setOperation(CGOpCode op, const std::vector< Argument< Base > > &arguments=std::vector< Argument< Base > >())
void setName(const std::string &name)
static std::unique_ptr< OperationNode< Base > > makeTemporaryNode(CGOpCode op, const std::vector< size_t > &info, const std::vector< Argument< Base > > &args)
const std::vector< size_t > & getInfo() const
size_t getHandlerPosition() const
std::vector< size_t > & getInfo()
const std::vector< Argument< Base > > & getArguments() const
CGOpCode getOperationType() const
std::vector< Argument< Base > > & getArguments()
void makeAlias(const Argument< Base > &other)
const std::string * getName() const
CodeHandler< Base > * getCodeHandler() const
bool GreaterThanZero(const cg::CG< Base > &x)