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

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "Functions.hpp"
       4             : #include "functions/Abs.hpp"
       5             : 
       6             : #include <thrust/extrema.h>
       7             : #include <thrust/complex.h>
       8             : 
       9             : namespace elsa
      10             : {
      11             :     namespace detail
      12             :     {
      13             :         struct MinMaxComp {
      14             :             template <class T>
      15             :             __host__ __device__ T operator()(const T& lhs, const T& rhs) const noexcept
      16      101662 :             {
      17      101662 :                 return lhs < rhs;
      18      101662 :             }
      19             : 
      20             :             template <class T>
      21             :             __host__ __device__ T operator()(const thrust::complex<T>& lhs,
      22             :                                              const thrust::complex<T>& rhs) const noexcept
      23          66 :             {
      24          66 :                 return elsa::abs(lhs) < elsa::abs(rhs);
      25          66 :             }
      26             :         };
      27             :     } // namespace detail
      28             : 
      29             :     /// @brief Compute the minimum element of the given vector
      30             :     ///
      31             :     /// The minimum is determined via the `operator<` of the iterators value type. If the vector is
      32             :     /// empty, a default constructed value type is returned.
      33             :     ///
      34             :     /// @ingroup reductions
      35             :     template <class InputIter>
      36             :     auto minElement(InputIter first, InputIter last) -> thrust::iterator_value_t<InputIter>
      37          42 :     {
      38          42 :         using data_t = thrust::iterator_value_t<InputIter>;
      39             : 
      40          42 :         auto iter = thrust::min_element(first, last, detail::MinMaxComp{});
      41          42 :         return iter == last ? data_t() : *iter;
      42          42 :     }
      43             : 
      44             :     /// @brief Compute the maximum element of the given vector
      45             :     ///
      46             :     /// The maximum is determined via the `operator<` of the iterators value type. If the vector is
      47             :     /// empty, a default constructed value type is returned.
      48             :     ///
      49             :     /// @ingroup reductions
      50             :     template <class InputIter>
      51             :     auto maxElement(InputIter first, InputIter last) -> thrust::iterator_value_t<InputIter>
      52          46 :     {
      53          46 :         using data_t = thrust::iterator_value_t<InputIter>;
      54             : 
      55          46 :         auto iter = thrust::max_element(first, last, detail::MinMaxComp{});
      56          46 :         return iter == last ? data_t() : *iter;
      57          46 :     }
      58             : } // namespace elsa

Generated by: LCOV version 1.14