1#ifndef CPPAD_CG_OPERATION_STACK_HPP
2#define CPPAD_CG_OPERATION_STACK_HPP
24enum class StackNavigationStep {
56 inline size_t argumentIndex()
const {
69 size_t parentNodeScope;
70 StackNavigationStep nextStep;
76 parentNodeScope(parentNodeScope),
77 nextStep(StackNavigationStep::Analyze) {
87template<
class Element>
90 std::vector<Element> _stack;
96 inline bool empty()
const {
97 return _stack.empty();
100 inline size_t size()
const {
101 return _stack.size();
104 inline void pop_back() {
109 return _stack.back();
112 template<
class...
Args>
113 inline void emplace_back(
Args&&...
args) {
114 if (_stack.size() == _stack.capacity()) {
115 _stack.reserve((_stack.size() * 3) / 2 + 1);
117 _stack.emplace_back(std::forward<Args>(
args)...);
120 inline Element& operator[](
size_t i) {
129 size_t parentNodeScope) {
134 if (
itArg->getOperation() !=
nullptr) {
135 size_t index = std::distance(begin(
args),
itArg.base()) - 1;
136 this->emplace_back(node, index, parentNodeScope);
150 if (
itArg->getOperation() !=
nullptr) {
151 size_t index = std::distance(begin(
args),
itArg.base()) - 1;
152 this->emplace_back(node, index);
177template<
class Base,
typename FunctionAnalysis,
typename FunctionPostProcess>
193 while (!stack.empty()) {
195 if (stack.back().nextStep == StackNavigationStep::Analyze) {
196 size_t i = stack.size() - 1;
201 stack[
i].nextStep = StackNavigationStep::ChildrenVisited;
203 stack[
i].nextStep = StackNavigationStep::Exit;
205 }
else if (stack.back().nextStep == StackNavigationStep::ChildrenVisited) {
207 stack.back().nextStep = StackNavigationStep::Exit;
230template<
class Base,
typename FunctionAnalysis>
241 stack.pushNodeArguments(
root);
244 while (!stack.empty()) {
245 auto nodeEl = stack.back();
static std::unique_ptr< OperationNode< Base > > makeTemporaryNode(CGOpCode op, const std::vector< size_t > &info, const std::vector< Argument< Base > > &args)
const std::vector< Argument< Base > > & getArguments() const
bool GreaterThanZero(const cg::CG< Base > &x)