3 #include <torch/csrc/python_headers.h> 5 #include <torch/csrc/DynamicTypes.h> 6 #include <torch/csrc/THP.h> 7 #include <torch/csrc/autograd/variable.h> 8 #include <ATen/core/interned_strings.h> 9 #include <ATen/core/ivalue.h> 10 #include <torch/csrc/jit/pybind_utils.h> 11 #include <torch/csrc/jit/tracer.h> 12 #include <torch/csrc/utils/pybind.h> 14 #include <pybind11/functional.h> 15 #include <pybind11/pybind11.h> 16 #include <pybind11/stl.h> 24 struct type_caster<
torch::jit::IValue> {
28 bool load(handle src,
bool) {
30 value = torch::jit::toIValue(src);
32 }
catch (std::exception& e) {
41 return torch::jit::toPyObject(std::move(src)).release();
46 struct type_caster<
torch::jit::Symbol> {
50 bool load(handle src,
bool) {
55 src_str = py::cast<std::string>(src);
56 }
catch (std::exception& e) {
59 value = torch::jit::Symbol::fromQualString(src_str);
67 return py::cast(std::string(src.toQualString()), return_value_policy::copy)
73 struct type_caster<
torch::jit::AttributeKind> {
75 PYBIND11_TYPE_CASTER(torch::jit::AttributeKind, _(
"AttributeKind"));
77 bool load(handle src,
bool) {
82 torch::jit::AttributeKind src,
86 std::string(torch::jit::toString(src)),
87 return_value_policy::copy)
93 using ListCasterBase = pybind11::detail::
96 struct type_caster<
std::vector<torch::jit::Node*>> : ListCasterBase {
98 const std::vector<torch::jit::Node*>& src,
101 return ListCasterBase::cast(src, return_value_policy::reference, parent);
104 const std::vector<torch::jit::Node*>* src,
105 return_value_policy pol,
107 return cast(*src, pol, parent);
117 static inline py::tuple tuple_tail(
const py::tuple& tup) {
118 py::tuple r(tup.size() - 1);
119 for (
size_t i = 1; i < tup.size(); i++) {