![](/img/trans.png)
[英]Getting pointers to the real and imaginary parts of a complex vector in C++
[英]How to switch the imaginary and reall parts for thrust complex vector
我想构造一个返回推力复数的结构,以切换虚部和实部。 但是我的代码无法工作。 错误是“不存在从“ thrust :: complex”到“ double”的合适转换函数”,这是我的代码。
struct im_harmonic
{
im_harmonic(){}
__device__ double operator()(thrust::complex<double>x){
thrust::complex<double> z;
z.real(x.imag());
z.imag(-x.real());
return z;
}
}
您的运算符声明要返回double
,但是在正文中您将返回一个类型thrust::complex
的值。 这就是为什么错误“没有从复数到双精度的适当转换”的原因。 为了克服这个问题,您可能必须声明您的运算符以返回一个复杂值:
thrust::complex<double> operator()(thrust::complex<double>x) { ..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.