无法将函数返回值转换为Python类型

2024-03-29 05:04:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用pyByD11将C++函数绑定到Python。 C++函数返回:

auto tree_fusion_depth_map(const hg::tree & tree_1, const hg::tree & tree_2, const hg::tree & tree_3) {
   //some code here
   return xt::eval(xt::view(depth, xt::range(0, nleaves)));

在python中调用函数时,我得到:

TypeError: Unable to convert function return value to a Python type! The signature was
    (arg0: higra.higram.Tree, arg1: higra.higram.Tree, arg2: higra.higram.Tree) -> xt::xtensor_container<xt::uvector<long, xsimd::aligned_allocator<long, 16ul> >, 1ul, (xt::layout_type)1, xt::xtensor_expression_tag>

这是C++代码中的Python模块和DOCTROM:

        PYBIND11_MODULE(mbfusion, m)
        {
            xt::import_numpy();

            m.doc() = R"pbdoc(
                An example higra extension
            )pbdoc";

            m.def("function", function, "An example function.");

        }

我如何解决这个问题


Tags: to函数treereturntypefunctionhglong