Caffe2 - C++ API
A deep learning, cross platform ML framework
python_tuples.h
1 #pragma once
2 
3 #include <torch/csrc/python_headers.h>
4 #include <torch/csrc/Exceptions.h>
5 #include <torch/csrc/utils/object_ptr.h>
6 #include <torch/csrc/utils/python_numbers.h>
7 
8 inline void THPUtils_packInt64Array(PyObject *tuple, size_t size, const int64_t *sizes) {
9  for (size_t i = 0; i != size; ++i) {
10  PyObject *i64 = THPUtils_packInt64(sizes[i]);
11  if (!i64) {
12  throw python_error();
13  }
14  PyTuple_SET_ITEM(tuple, i, i64);
15  }
16 }
17 
18 inline PyObject* THPUtils_packInt64Array(size_t size, const int64_t *sizes) {
19  THPObjectPtr tuple(PyTuple_New(size));
20  if (!tuple) throw python_error();
21  THPUtils_packInt64Array(tuple.get(), size, sizes);
22  return tuple.release();
23 }