UnboxingFunctions.h 1.0 KB

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