python - 无法将函数返回值转换为 Python 类型
问题描述
我想使用 pybind11 将 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 模块和文档字符串:
PYBIND11_MODULE(mbfusion, m)
{
xt::import_numpy();
m.doc() = R"pbdoc(
An example higra extension
)pbdoc";
m.def("function", function, "An example function.");
}
我该如何解决这个问题?
解决方案
推荐阅读
- java - Kotlin 对值由注释设置的变量返回 null
- elasticsearch - 如何停止logstash将logstash日志写入syslog?
- javascript - 从第 2 页开始无法访问输入控件
- django - 没有在带有 Docker 的 Django 应用程序上提交工作服
- sql - 使用 CASE 语句根据表 B 中的值更新表 A 中的列
- opencl - 使用向量类型来提高 OpenCL 内核性能
- r - x轴压在一起
- android - Android 10:“由于在 UI 线程被阻止时在不正确的线程上调用 WebView API 而检测到可能的死锁”
- android - 无法将我的应用上传到 Fabric、CrashLytics
- amazon-web-services - S3 存储桶权限更改时的电子邮件通知