Operating on thrust::complex types with thrust::transform

假装没事ソ 提交于 2019-12-02 13:38:35

The error message is quite descriptive:

thrust::abs<thrust::complex<...>> is a function which expects exactly one parameter, see thrust/detail/complex/arithmetic.h#L143:

template <typename ValueType>
  __host__ __device__
  inline ValueType abs(const complex<ValueType>& z){
  return hypot(z.real(),z.imag());
}

For your use case, you need to wrap that function by a functor:

struct complex_abs_functor
{
    template <typename ValueType>
    __host__ __device__
    ValueType operator()(const thrust::complex<ValueType>& z)
    {
        return thrust::abs(z);
    }
};

Finally, employ that functor here:

thrust::transform(d_vec1.begin(),
                  d_vec1.end(),
                  d_vec2.begin(),
                  complex_abs_functor());
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!