mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
This reverts commit 532b8a9e00.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82599
Approved by: https://github.com/albanD
30 lines
722 B
C++
30 lines
722 B
C++
#pragma once
|
|
#include <pybind11/pybind11.h>
|
|
#include <pybind11/stl.h>
|
|
#include <torch/csrc/jit/api/module.h>
|
|
#include <torch/csrc/utils/pybind.h>
|
|
|
|
namespace py = pybind11;
|
|
|
|
namespace torch {
|
|
namespace jit {
|
|
|
|
inline c10::optional<Module> as_module(const py::object& obj) {
|
|
if (py::isinstance(
|
|
obj, py::module::import("torch.jit").attr("ScriptModule"))) {
|
|
return py::cast<Module>(obj.attr("_c"));
|
|
}
|
|
return c10::nullopt;
|
|
}
|
|
|
|
inline c10::optional<Object> as_object(const py::object& obj) {
|
|
if (py::isinstance(
|
|
obj, py::module::import("torch.jit").attr("RecursiveScriptClass"))) {
|
|
return py::cast<Object>(obj.attr("_c"));
|
|
}
|
|
return c10::nullopt;
|
|
}
|
|
|
|
} // namespace jit
|
|
} // namespace torch
|