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

          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       28004 :             {
      18       28004 :                 using U = std::common_type_t<T, data_t>;
      19       28004 :                 return static_cast<U>(x) - static_cast<U>(scalar_);
      20       28004 :             }
      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       19097 :             {
      32       19097 :                 using U = std::common_type_t<T, data_t>;
      33       19097 :                 return static_cast<U>(scalar_) - static_cast<U>(x);
      34       19097 :             }
      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

Generated by: LCOV version 1.14