3 #include <ATen/core/ivalue.h> 11 using Stack = std::vector<IValue>;
12 using Operation = std::function<int(Stack&)>;
29 static inline IValue& peek(Stack& stack,
size_t i,
size_t N) {
30 return *(stack.end() - N + i);
32 static inline const IValue& peek(
const Stack& stack,
size_t i,
size_t N) {
33 return *(stack.end() - N + i);
45 return peekSlice(stack, 0, N, N);
47 static inline void drop(Stack& stack,
size_t n) {
48 stack.erase(stack.end() - n, stack.end());
50 static inline IValue pop(Stack& stack) {
51 auto r = std::move(stack.back());
55 static inline std::vector<IValue> pop(Stack& stack,
size_t n) {
56 std::vector<IValue> result;
58 for (
size_t i = 0; i < n; ++i) {
59 result.push_back(std::move(peek(stack, i, n)));
71 template <
typename... Types>
72 static inline void pop(Stack& stack, Types&... args) {
74 constexpr
size_t N =
sizeof...(args);
76 (args = std::move(peek(stack, i++, N)).template to<Types>(), 0)...};
80 template <
typename... Types>
81 static inline void push(Stack& stack, Types&&... args) {
82 (void)std::initializer_list<int>{(stack.emplace_back(std::forward<Types>(args)), 0)...};
90 inline void pack(Stack& stack,
T&& v) {
91 stack.emplace_back(std::forward<T>(v));
94 template <std::size_t remaining,
typename... Args>
97 static void execute(Stack& stack, std::tuple<Args...>&& t) {
101 pack(stack, std::get<
sizeof...(Args) - remaining>(std::move(t)));
106 template <
typename... Args>
108 static void execute(Stack& stack, std::tuple<Args...>&& t){};
111 template <
typename... Args>
112 inline void pack(Stack& stack, std::tuple<Args...>&& t) {
113 TuplePacker<
sizeof...(Args), Args...>::execute(stack, std::move(t));
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...