Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 返回c+中std::variant的numpy数组+;_Python_C++_Numpy_Pybind11 - Fatal编程技术网

Python 返回c+中std::variant的numpy数组+;

Python 返回c+中std::variant的numpy数组+;,python,c++,numpy,pybind11,Python,C++,Numpy,Pybind11,我试图创建一个pybd11接口,它将两个编号数组的元组从C++返回到Python。lambda表达式中的子函数lttb返回两个类型为std::vector和std::vector的向量 如果我直接返回向量,那么pybind11/stl.h头可以很好地处理转换。创建doublenumpy数组也可以完美地工作。但是,当尝试创建std::variant的numpy数组时,我得到以下错误 ..\subprojects\pybind11\include\pybind11/numpy.h(1159): er

我试图创建一个pybd11接口,它将两个编号数组的元组从C++返回到Python。lambda表达式中的子函数lttb返回两个类型为
std::vector
std::vector
的向量

如果我直接返回向量,那么
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
有一种方法可以注册结构化类型(),以防止出现此错误消息,但是我只看到一种方法可以使用
struct
而不是
std::variant
来实现此功能。有人知道如何创建
std::variant
的numpy数组吗?应该没有那么难,因为转换
std::vector
是现成的。这是密码

    .def("lttb",
         [&](ScopeDataElement& data,
             const std::pair<double, double>& limit,
             int64_t masterTick,
             long double samplingTime,
             size_t destinationSize) {
           auto&& [x, y] =
             data.lttb(limit, masterTick, samplingTime, destinationSize);
           using T = std::decay_t<decltype(x)>::value_type;
           using U = std::decay_t<decltype(y)>::value_type;
           auto arrx = py::array_t<T>(x.size(), x.data());
           auto arry = py::array_t<U>(y.size(), y.data());
           return py::make_tuple(arrx, arry);
         })
.def(“lttb”,
[&](范围数据元素和数据,
常数标准::对和限制,
int64_t masterTick,
长的双采样时间,
尺寸(目标尺寸){
自动&[x,y]=
数据.lttb(限制、masterTick、采样时间、目标大小);
使用T=std::decage\u T::value\u type;
使用U=std::decage\U t::value\U type;
auto arrx=py::array_t(x.size(),x.data());
auto arry=py::array_t(y.size(),y.data());
返回py::make_tuple(arrx,arry);
})