LCOV - code coverage report
Current view: top level - elsa/storage/transforms - Add.h (source / functions) Hit Total Coverage
Test: coverage-all.lcov Lines: 11 11 100.0 %
Date: 2024-05-16 04:22:26 Functions: 22 22 100.0 %

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

Generated by: LCOV version 1.14