文档很好地说明了如何组合简单的函数对象以传递给 boost::compute 提供的任何算法。还有一个提供的链接 [Custom OpenCL Functions in C++ with Boost.Compute][1],但同时已失效。 boost 计算文档没有提及任何有关嵌套算法的内容:(这应该是稀疏矩阵 (_rM) 与向量 (_rX) 相乘的实现。)
const std::vector<double> _rM, _rX;
const std::vector<std::size_t> _rRowStart;
const std::vector<unsigned int> _rCol;
std::transform(
_rRowStart.begin(),
std::prev(_rRowStart.end()),
std::next(_rRowStart.begin()),
_rY.begin(),
[&](const POS _iRowStart, const POS _iRowEnd)
{ return std::inner_product(
_rM.begin() + _iRowStart,
_rM.begin() + _iRowEnd,
boost::make_permutation_iterator(_rX.begin(), _rCol.begin() + _iRowStart),
0.0
);
}
);
那么如何实现一个函数对象,进而从 boost::compute 调用另一种算法呢?如何将变量引用传递给该函数对象(&_rM、&_rX、&_rCol)? 我希望在 boost::compute 中实现上述算法。 (inner_product 也可以在没有 boost::permutation_iterator 的情况下实现,方法是使用两个输入范围和两个函数对象,一个执行累加 (std::plus),另一个执行乘法和排列。) [1]:http://kylelutz.blogspot.com/2014/03/custom-opencl-functions-in-c-with.html