brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.9 KiB · ec51440 Raw
116 lines · plain
1//  Copyright John Maddock 2018.2//  Use, modification and distribution are subject to the3//  Boost Software License, Version 1.0. (See accompanying file4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)5 6//7// Tools for operator on complex as well as scalar types.8//9 10#ifndef BOOST_MATH_TOOLS_COMPLEX_HPP11#define BOOST_MATH_TOOLS_COMPLEX_HPP12 13#include <boost/math/tools/config.hpp>14#include <boost/math/tools/is_detected.hpp>15 16#ifdef BOOST_MATH_ENABLE_CUDA17 18#include <cuda/std/utility>19#include <cuda/std/complex>20 21namespace boost {22namespace math {23 24template <typename T>25using complex = cuda::std::complex<T>;26 27} // namespace math28} // namespace boost29 30#else31 32#include <utility>33#include <complex>34 35namespace boost {36namespace math {37 38template <typename T>39using complex = std::complex<T>;40 41} // namespace math42} // namespace boost43 44#endif45 46namespace boost {47   namespace math {48      namespace tools {49 50         namespace detail {51         template <typename T, typename = void>52         struct is_complex_type_impl53         {54            static constexpr bool value = false;55         };56 57         #ifndef BOOST_MATH_ENABLE_CUDA58         template <typename T>59         struct is_complex_type_impl<T, void_t<decltype(std::declval<T>().real()), 60                                               decltype(std::declval<T>().imag())>>61         {62            static constexpr bool value = true;63         };64         #else65         template <typename T>66         struct is_complex_type_impl<T, void_t<decltype(cuda::std::declval<T>().real()), 67                                               decltype(cuda::std::declval<T>().imag())>>68         {69            static constexpr bool value = true;70         };71         #endif72         } // Namespace detail73 74         template <typename T>75         struct is_complex_type : public detail::is_complex_type_impl<T> {};76         77         //78         // Use this trait to typecast integer literals to something79         // that will interoperate with T:80         //81         template <class T, bool = is_complex_type<T>::value>82         struct integer_scalar_type83         {84            typedef int type;85         };86         template <class T>87         struct integer_scalar_type<T, true>88         {89            typedef typename T::value_type type;90         };91         template <class T, bool = is_complex_type<T>::value>92         struct unsigned_scalar_type93         {94            typedef unsigned type;95         };96         template <class T>97         struct unsigned_scalar_type<T, true>98         {99            typedef typename T::value_type type;100         };101         template <class T, bool = is_complex_type<T>::value>102         struct scalar_type103         {104            typedef T type;105         };106         template <class T>107         struct scalar_type<T, true>108         {109            typedef typename T::value_type type;110         };111 112 113} } }114 115#endif // BOOST_MATH_TOOLS_COMPLEX_HPP116