Line data Source code
1 : #pragma once 2 : 3 : #include "TypeTraits.hpp" 4 : #include "functions/Imag.hpp" 5 : 6 : #include <thrust/transform.h> 7 : #include <thrust/copy.h> 8 : #include <thrust/iterator/iterator_traits.h> 9 : 10 : namespace elsa 11 : { 12 : /// @brief Extract the imaginary part of a range. If input range is not complex, it is treated 13 : /// as complex numbers with an imaginary part of `0` 14 : /// 15 : /// @ingroup transforms 16 : template <class InputIter, class OutIter> 17 : void imag(InputIter first, InputIter last, OutIter out) 18 5 : { 19 5 : using xdata_t = thrust::iterator_value_t<InputIter>; 20 5 : using outdata_t = thrust::iterator_value_t<OutIter>; 21 : 22 : // If the input is not complex, the imaginary part will be 0 23 5 : if constexpr (!is_complex_v<xdata_t>) { 24 2 : thrust::fill_n(out, thrust::distance(first, last), outdata_t(0)); 25 2 : } else { 26 2 : thrust::transform(first, last, out, elsa::fn::imag); 27 2 : } 28 5 : } 29 : } // namespace elsa