1 #include <torch/csrc/utils/tensor_list.h> 3 #include <torch/csrc/Exceptions.h> 4 #include <torch/csrc/utils/auto_gil.h> 5 #include <torch/csrc/utils/python_scalars.h> 9 namespace torch {
namespace utils {
11 static PyObject* recursive_to_list(
13 ScalarType scalarType, int64_t elementSize)
15 int64_t ndim = sizes.
size();
17 return torch::utils::load_scalar(data, scalarType);
22 for (int64_t i = 0; i < n; i++) {
23 PyObject* obj = recursive_to_list(data, sizes, strides, dim + 1, scalarType, elementSize);
25 PyList_SET_ITEM(list.get(), i, obj);
26 data += strides[dim] * elementSize;
28 return list.release();
31 PyObject* tensor_to_list(
const Tensor& tensor) {
33 if (data.type().backend() != Backend::CPU) {
35 data = data.toBackend(Backend::CPU);
38 return recursive_to_list(
39 (
char*)data.data_ptr(), data.sizes(), data.strides(), 0,
caffe2::TypeMeta dtype() const noexcept
Returns a Tensor's dtype (TypeMeta). Defined in TensorMethods.h.
constexpr size_t size() const
size - Get the array size.
Flush-To-Zero and Denormals-Are-Zero mode.