gpt4 book ai didi

c++ - 推力:不支持运算符 '*'

转载 作者:行者123 更新时间:2023-11-27 22:50:24 28 4
gpt4 key购买 nike

我有以下函数,用于用从 -time/2 到 time/2 的步长和步长 dt 填充 vector t:

#define THRUST_PREC thrust::complex<double>
__host__ void generate_time(thrust::device_vector<THRUST_PREC> *t, const double dt, const double time)
{
THRUST_PREC start = -time / 2.0;
THRUST_PREC step = dt;
thrust::sequence((*t).begin(), (*t).end(), start, step);
}

编译时,我得到错误:没有运算符“*”匹配这些操作数。为什么?有没有办法像我一样填充 vector ,或者我应该用旧方法(又名循环)填充它?

编辑:完整错误:错误 1 ​​错误:没有运算符“*”匹配这些操作数 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v7.5\include\thrust\system\detail\generic\sequence.inl 48 1 FFT_test

最佳答案

看起来像是thrust::complex的bug . const thrust:complex<double>之间的乘法运算和 signed long未定义。

/usr/local/cuda/bin/../targets/x86_64-linux/include/thrust/system/detail/generic/sequence.inl(48):
error: no operator "*" matches these operands
operand types are: const thrust::complex<double> * signed long
detected during:
....

但奇怪的是,你可以使用 thrust::transform反而。以下代码有效。

#define THRUST_PREC thrust::complex<double>
__host__ void generate_time(thrust::device_vector<THRUST_PREC> *t, const double dt, const double time)
{
THRUST_PREC start = -time / 2.0;
THRUST_PREC step = dt;
thrust::transform(thrust::make_counting_iterator(0),
thrust::make_counting_iterator(0) + t->size(),
t->begin(),
start + step * _1);
}

无论哪种方式,内部实现都使用索引(类型为 signed long 中的 thrust::sequence )来计算所需的表达式序列

start + step * index;

物防thrust::sequence来自工作的是operator *(...)没有很好地重载。

thrust::complex<double> a(1,1);
double double_b = 4;
float float_b = 4;
int int_b = 4;
long long_b = 4;

a *= double_b; // ok
a *= float_b; // ok
a *= int_b; // ok
a *= long_b; // ok

std::cout << a * double_b << std::endl; // ok
std::cout << a * float_b << std::endl; // error
std::cout << a * int_b << std::endl; // error
std::cout << a * long_b << std::endl; // error

关于c++ - 推力:不支持运算符 '*',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37705846/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com