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