有没有办法用 pow
来转换推力矢量?功能?换句话说,我想变换每个元素x
向量到pow(x,a)
,与 a
一个常数。
最佳答案
请引用Section Transformations在 Thrust 快速入门指南中了解如何编写具有初始化参数的仿函数。
struct saxpy_functor
{
const float a;
saxpy_functor(float _a) : a(_a) {}
__host__ __device__
float operator()(const float& x, const float& y) const {
return a * x + y;
}
};
关于cuda - 使用 CUDA Thrust 进行逐元素幂运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14353459/