pytorch/torch/csrc/jit/script/module_python.h
Mikhail Zolotukhin 360640bc9c Extract Python-specific SugaredValues to a separate file from init.cpp. (#19986)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/19986
ghimport-source-id: 67f5fec4b5b2114f2922505a7743ed27e6d7e6cc

Differential Revision: D15160820

Pulled By: ZolotukhinM

fbshipit-source-id: e39238db8f30a8809891bff8a2fe39977124f6ca
2019-04-30 19:38:23 -07:00

23 lines
502 B
C++

#pragma once
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <torch/csrc/jit/script/module.h>
namespace py = pybind11;
namespace torch {
namespace jit {
namespace script {
inline std::shared_ptr<Module> as_module(const py::object& obj) {
if (py::isinstance(
obj, py::module::import("torch.jit").attr("ScriptModule"))) {
return py::cast<std::shared_ptr<Module>>(obj.attr("_c"));
}
return nullptr;
}
} // namespace script
} // namespace jit
} // namespace torch