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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "ContiguousStorage.h"
       4             : 
       5             : #include <thrust/transform.h>
       6             : #include <thrust/iterator/iterator_traits.h>
       7             : 
       8             : namespace elsa
       9             : {
      10             :     /// @brief Clip input range to `minval` and `maxval`
      11             :     /// @ingroup transforms
      12             :     template <class Iter, class OutIter, class T = thrust::iterator_value_t<Iter>,
      13             :               class U = thrust::iterator_value_t<Iter>>
      14             :     void clip(Iter first, Iter last, OutIter out, const T& minval, const U& maxval)
      15         186 :     {
      16         186 :         using data_t = thrust::iterator_value_t<Iter>;
      17             : 
      18        5206 :         thrust::transform(first, last, out, [=] __host__ __device__(const data_t& x) {
      19        5206 :             if (x < static_cast<data_t>(minval)) {
      20        2703 :                 return static_cast<data_t>(minval);
      21        2703 :             } else if (x > static_cast<data_t>(maxval)) {
      22          48 :                 return static_cast<data_t>(maxval);
      23        2455 :             } else {
      24        2455 :                 return x;
      25        2455 :             }
      26        5206 :         });
      27         186 :     }
      28             : 
      29             :     /// @brief Clip input range to `0` and `maxval`
      30             :     /// @ingroup transforms
      31             :     template <class Iter, class OutIter, class T = thrust::iterator_value_t<Iter>>
      32             :     void clip(Iter first, Iter last, OutIter out, const T& maxval)
      33             :     {
      34             :         using data_t = thrust::iterator_value_t<Iter>;
      35             :         return clip(first, last, out, data_t(0), static_cast<data_t>(maxval));
      36             :     }
      37             : } // namespace elsa

Generated by: LCOV version 1.14