xref: /aosp_15_r20/external/pytorch/torch/csrc/DynamicTypes.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 
3 // Provides conversions between Python tensor objects and at::Tensor.
4 
5 #include <torch/csrc/python_headers.h>
6 
7 #include <ATen/Device.h>
8 #include <c10/core/Backend.h>
9 #include <c10/core/Layout.h>
10 #include <c10/core/ScalarType.h>
11 #include <c10/core/ScalarTypeToTypeMeta.h>
12 #include <torch/csrc/Export.h>
13 
14 #include <memory>
15 #include <string>
16 
17 struct THPDtype;
18 struct THPLayout;
19 
20 namespace c10 {
21 struct Storage;
22 }
23 
24 namespace torch {
25 void registerDtypeObject(THPDtype* dtype, at::ScalarType scalarType);
26 void registerLayoutObject(THPLayout* thp_layout, at::Layout layout);
27 
28 TORCH_PYTHON_API PyObject* createPyObject(const at::Storage& storage);
29 at::Storage createStorage(PyObject* obj);
30 std::tuple<at::Storage, at::ScalarType, bool> createStorageGetType(
31     PyObject* obj);
32 bool isStorage(PyObject* obj);
33 
34 // Both methods below return a borrowed reference!
35 TORCH_PYTHON_API THPDtype* getTHPDtype(at::ScalarType scalarType);
36 THPLayout* getTHPLayout(at::Layout layout);
37 } // namespace torch
38