在c ++

问题描述

我正在尝试创建一个pybind11接口,该接口将从C ++返回两个numpy数组的元组。 lambda表达式内的子函数lttb返回两个std::vector<double>std::vector<std::variant<uint32_t,in64_t,double>>类型的向量。

如果我直接返回向量,则pybind11/stl.h标头会很好地处理转换。 double numpy数组的创建也可以正常工作。但是,当尝试创建std::variant的numpy数组时,出现以下错误

..\subprojects\pybind11\include\pybind11/numpy.h(1159): error C2338: Attempt to use a non-POD or unimplemented POD type as a numpy dtype

有一种方法可以注册结构化类型(https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html#structured-types)来防止出现此错误消息,但是我只看到一种使用struct而不是{{1} }。有人知道如何创建std::variant的Numpy数组吗?应该不难,因为std::variant的转换是开箱即用的。这是代码

std::vector<std::variant<...>>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)