xref: /aosp_15_r20/external/pytorch/aten/src/ATen/templates/UnboxingFunctions.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 // ${generated_comment}
2 
3 // Generated by tools/jit/gen_unboxing.py. This file declares code generated boxed C++ functions for operators,
4 // base off of native_functions.yaml (or similar yaml file with the same syntax). The definition of such a boxed
5 // function will pop out IValues from the stack then convert them into the correct C++ types based on given schema. This
6 // unboxing logic is an alternative to template-based metaprogramming unboxing.
7 
8 #pragma once
9 
10 #include <ATen/ATen.h>
11 namespace at {
12 namespace unboxing {
13 namespace {
14 
15 template<typename T, size_t N>
as_array(const c10::List<c10::IValue> & list)16 std::array<T, N> as_array(const c10::List<c10::IValue>& list) {
17     std::array<T, N> res;
18     AT_ASSERT(list.size() == N);
19     std::vector<T> vec;
20     for (c10::IValue elem : list) {
21         vec.push_back(elem.to<T>());
22     }
23     std::copy(vec.begin(), vec.end(), res.begin());
24     return res;
25 }
26 }  // namespace <anonymous>
27 using Stack = std::vector<c10::IValue>;
28 // Generated function declaration
29 ${declarations}
30 
31 } // namespace unboxing
32 } // namespace at
33