Line data Source code
1 : #pragma once 2 : 3 : #include "Functions.hpp" 4 : 5 : #include <thrust/transform.h> 6 : 7 : namespace elsa 8 : { 9 : namespace detail 10 : { 11 : template <class T> 12 : struct SubVectorScalar { 13 120 : SubVectorScalar(T scalar) : scalar_(scalar) {} 14 : 15 : template <class data_t> 16 : __host__ __device__ auto operator()(const data_t& x) -> std::common_type_t<T, data_t> 17 29301 : { 18 29301 : using U = std::common_type_t<T, data_t>; 19 29301 : return static_cast<U>(x) - static_cast<U>(scalar_); 20 29301 : } 21 : 22 : T scalar_; 23 : }; 24 : 25 : template <class T> 26 : struct SubScalarVector { 27 29 : SubScalarVector(T scalar) : scalar_(scalar) {} 28 : 29 : template <class data_t> 30 : __host__ __device__ auto operator()(const data_t& x) -> std::common_type_t<T, data_t> 31 19615 : { 32 19615 : using U = std::common_type_t<T, data_t>; 33 19615 : return static_cast<U>(scalar_) - static_cast<U>(x); 34 19615 : } 35 : 36 : T scalar_; 37 : }; 38 : } // namespace detail 39 : 40 : /// @brief Compute the component wise subtraction of two vectors 41 : /// @ingroup transforms 42 : template <class InputIter1, class InputIter2, class OutIter> 43 : void sub(InputIter1 xfirst, InputIter1 xlast, InputIter2 yfirst, OutIter out) 44 8323 : { 45 8323 : thrust::transform(xfirst, xlast, yfirst, out, elsa::minus{}); 46 8323 : } 47 : 48 : /// @brief Compute the component wise subtraction of a vectors and a scalar 49 : /// @ingroup transforms 50 : template <class data_t, class InputIter, class OutIter> 51 : void subScalar(InputIter first, InputIter last, const data_t& scalar, OutIter out) 52 120 : { 53 : // TODO: Find out why a lambda doesn't work here! 54 120 : thrust::transform(first, last, out, detail::SubVectorScalar(scalar)); 55 120 : } 56 : 57 : /// @brief Compute the component wise subtraction of a scalar and a vector 58 : /// @ingroup transforms 59 : template <class data_t, class InputIter, class OutIter> 60 : void subScalar(const data_t& scalar, InputIter first, InputIter last, OutIter out) 61 29 : { 62 : // TODO: Find out why a lambda doesn't work here! 63 29 : thrust::transform(first, last, out, detail::SubScalarVector(scalar)); 64 29 : } 65 : } // namespace elsa