在 Thrust 中将原始数据转换为复数向量

Convert raw data to a vector of complex numbers in Thrust

我有一个指向交错格式复数原始数据的指针,即实部和虚部交替存储 - R I R I R I ...

如何将其转换为 thrust::complex 的主机(或设备)向量而不产生额外的副本? 以下不起作用 -

double dos[8] = {9.3252,2.3742,7.2362,5.3562,2.3323,2.2322,7.2362,3.2352};
thrust::host_vector<thrust::complex<double > > comp(dos, dos+8);

刚投。像这样:

double dos[8] = {9.3252,2.3742,7.2362,5.3562,2.3323,2.2322,7.2362,3.2352};
typedef thrust::complex<double> cdub;
cdub* cdos = reinterpret_cast<cdub*>(&dos[0]);
thrust::host_vector<cdub> comp(cdos, cdos+4);

应该可以。