3 #include <pybind11/pybind11.h> 4 #include <torch/csrc/utils/structseq.h> 5 #include <torch/csrc/utils/object_ptr.h> 14 inline bool isStructSeq(pybind11::handle input) {
15 return pybind11::cast<std::string>(input.get_type().attr(
"__module__")) ==
"torch.return_types";
18 inline bool isStructSeq(PyObject* obj) {
19 return isStructSeq(pybind11::handle(obj));
22 inline bool isTuple(pybind11::handle input) {
23 if (PyTuple_Check(input.ptr())) {
26 #if PY_MAJOR_VERSION == 2 27 return isStructSeq(input);
33 inline bool isTuple(PyObject* obj) {
34 return isTuple(pybind11::handle(obj));
42 inline THPObjectPtr maybeAsTuple(PyStructSequence *obj) {
43 #if PY_MAJOR_VERSION == 2 44 return THPObjectPtr(torch::utils::structseq_slice(obj, 0, Py_SIZE(obj)));
53 return maybeAsTuple((PyStructSequence *)obj);