xref: /aosp_15_r20/external/pytorch/torch/csrc/utils/tensor_numpy.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 
3 #include <ATen/core/Tensor.h>
4 #include <torch/csrc/python_headers.h>
5 
6 namespace torch::utils {
7 
8 PyObject* tensor_to_numpy(const at::Tensor& tensor, bool force = false);
9 at::Tensor tensor_from_numpy(PyObject* obj, bool warn_if_not_writeable = true);
10 
11 int aten_to_numpy_dtype(const at::ScalarType scalar_type);
12 at::ScalarType numpy_dtype_to_aten(int dtype);
13 
14 bool is_numpy_available();
15 bool is_numpy_int(PyObject* obj);
16 bool is_numpy_bool(PyObject* obj);
17 bool is_numpy_scalar(PyObject* obj);
18 
19 void warn_numpy_not_writeable();
20 at::Tensor tensor_from_cuda_array_interface(PyObject* obj);
21 
22 void validate_numpy_for_dlpack_deleter_bug();
23 bool is_numpy_dlpack_deleter_bugged();
24 
25 } // namespace torch::utils
26