Line data Source code
1 : #pragma once 2 : 3 : #include <thrust/transform.h> 4 : 5 : namespace elsa 6 : { 7 : namespace detail 8 : { 9 : template <class data_t> 10 : struct LincombFunctor { 11 : data_t a_; 12 : data_t b_; 13 : 14 5178 : LincombFunctor(data_t a, data_t b) : a_(a), b_(b) {} 15 : 16 : __host__ __device__ data_t operator()(const data_t& x, const data_t& y) const 17 243209 : { 18 243209 : return a_ * x + b_ * y; 19 243209 : } 20 : }; 21 : } // namespace detail 22 : 23 : /// @brief Compute the linear combination of \f$a * x + b * y\f$, where 24 : /// \f$x\f$ and \f$y\f$ are vectors given as iterators, and written to the output 25 : /// iterator 26 : /// 27 : /// @ingroup transforms 28 : template <class data_t, class InputIter1, class InputIter2, class OutIter> 29 : void lincomb(data_t a, InputIter1 first1, InputIter1 last1, data_t b, InputIter2 first2, 30 : OutIter out) 31 5178 : { 32 5178 : thrust::transform(first1, last1, first2, out, detail::LincombFunctor<data_t>{a, b}); 33 5178 : } 34 : } // namespace elsa