11 #ifndef EIGEN_MATHFUNCTIONS_H
12 #define EIGEN_MATHFUNCTIONS_H
16 #define EIGEN_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406L
17 #define EIGEN_LOG2E 1.442695040888963407359924681001892137426645954152985934135449406931109219L
18 #define EIGEN_LN2 0.693147180559945309417232121458176568075500134360255254120680009493393621L
20 #include "./InternalHeaderCheck.h"
46 template<
typename T,
typename dummy =
void>
47 struct global_math_functions_filtering_base
52 template<
typename T>
struct always_void {
typedef void type; };
55 struct global_math_functions_filtering_base
57 typename always_void<typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl>::type
60 typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type;
63 #define EIGEN_MATHFUNC_IMPL(func, scalar) Eigen::internal::func##_impl<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>
64 #define EIGEN_MATHFUNC_RETVAL(func, scalar) typename Eigen::internal::func##_retval<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>::type
70 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
71 struct real_default_impl
73 typedef typename NumTraits<Scalar>::Real RealScalar;
75 static inline RealScalar run(
const Scalar& x)
81 template<
typename Scalar>
82 struct real_default_impl<Scalar,true>
84 typedef typename NumTraits<Scalar>::Real RealScalar;
86 static inline RealScalar run(
const Scalar& x)
93 template<
typename Scalar>
struct real_impl : real_default_impl<Scalar> {};
95 #if defined(EIGEN_GPU_COMPILE_PHASE)
97 struct real_impl<std::complex<T> >
101 static inline T run(
const std::complex<T>& x)
108 template<
typename Scalar>
111 typedef typename NumTraits<Scalar>::Real type;
118 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
119 struct imag_default_impl
121 typedef typename NumTraits<Scalar>::Real RealScalar;
123 static inline RealScalar run(
const Scalar&)
125 return RealScalar(0);
129 template<
typename Scalar>
130 struct imag_default_impl<Scalar,true>
132 typedef typename NumTraits<Scalar>::Real RealScalar;
134 static inline RealScalar run(
const Scalar& x)
141 template<
typename Scalar>
struct imag_impl : imag_default_impl<Scalar> {};
143 #if defined(EIGEN_GPU_COMPILE_PHASE)
145 struct imag_impl<std::complex<T> >
147 typedef T RealScalar;
149 static inline T run(
const std::complex<T>& x)
156 template<
typename Scalar>
159 typedef typename NumTraits<Scalar>::Real type;
166 template<
typename Scalar>
169 typedef typename NumTraits<Scalar>::Real RealScalar;
171 static inline RealScalar& run(Scalar& x)
173 return reinterpret_cast<RealScalar*
>(&x)[0];
176 static inline const RealScalar& run(
const Scalar& x)
178 return reinterpret_cast<const RealScalar*
>(&x)[0];
182 template<
typename Scalar>
183 struct real_ref_retval
185 typedef typename NumTraits<Scalar>::Real & type;
192 template<
typename Scalar,
bool IsComplex>
193 struct imag_ref_default_impl
195 typedef typename NumTraits<Scalar>::Real RealScalar;
197 static inline RealScalar& run(Scalar& x)
199 return reinterpret_cast<RealScalar*
>(&x)[1];
202 static inline const RealScalar& run(
const Scalar& x)
204 return reinterpret_cast<RealScalar*
>(&x)[1];
208 template<
typename Scalar>
209 struct imag_ref_default_impl<Scalar, false>
211 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
212 static inline Scalar run(Scalar&)
216 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
217 static inline const Scalar run(
const Scalar&)
223 template<
typename Scalar>
224 struct imag_ref_impl : imag_ref_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
226 template<
typename Scalar>
227 struct imag_ref_retval
229 typedef typename NumTraits<Scalar>::Real & type;
236 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
237 struct conj_default_impl
240 static inline Scalar run(
const Scalar& x)
246 template<
typename Scalar>
247 struct conj_default_impl<Scalar,true>
250 static inline Scalar run(
const Scalar& x)
257 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
258 struct conj_impl : conj_default_impl<Scalar, IsComplex> {};
260 template<
typename Scalar>
270 template<
typename Scalar,
bool IsComplex>
271 struct abs2_impl_default
273 typedef typename NumTraits<Scalar>::Real RealScalar;
275 static inline RealScalar run(
const Scalar& x)
281 template<
typename Scalar>
282 struct abs2_impl_default<Scalar, true>
284 typedef typename NumTraits<Scalar>::Real RealScalar;
286 static inline RealScalar run(
const Scalar& x)
288 return x.real()*x.real() + x.imag()*x.imag();
292 template<
typename Scalar>
295 typedef typename NumTraits<Scalar>::Real RealScalar;
297 static inline RealScalar run(
const Scalar& x)
299 return abs2_impl_default<Scalar,NumTraits<Scalar>::IsComplex>::run(x);
303 template<
typename Scalar>
306 typedef typename NumTraits<Scalar>::Real type;
313 template<
typename Scalar>
317 static EIGEN_ALWAYS_INLINE Scalar run(
const Scalar& x)
319 EIGEN_USING_STD(
sqrt);
325 template<
typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_sqrt(
const std::complex<T>& a_x);
330 struct sqrt_impl<std::complex<T> >
333 static EIGEN_ALWAYS_INLINE std::complex<T> run(
const std::complex<T>& x)
335 return complex_sqrt<T>(x);
339 template<
typename Scalar>
350 template<
typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_rsqrt(
const std::complex<T>& a_x);
353 struct rsqrt_impl<std::complex<T> >
356 static EIGEN_ALWAYS_INLINE std::complex<T> run(
const std::complex<T>& x)
358 return complex_rsqrt<T>(x);
362 template<
typename Scalar>
372 template<
typename Scalar,
bool IsComplex>
373 struct norm1_default_impl;
375 template<
typename Scalar>
376 struct norm1_default_impl<Scalar,true>
378 typedef typename NumTraits<Scalar>::Real RealScalar;
380 static inline RealScalar run(
const Scalar& x)
382 EIGEN_USING_STD(
abs);
383 return abs(x.real()) +
abs(x.imag());
387 template<
typename Scalar>
388 struct norm1_default_impl<Scalar, false>
391 static inline Scalar run(
const Scalar& x)
393 EIGEN_USING_STD(
abs);
398 template<
typename Scalar>
399 struct norm1_impl : norm1_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
401 template<
typename Scalar>
404 typedef typename NumTraits<Scalar>::Real type;
411 template<
typename Scalar>
struct hypot_impl;
413 template<
typename Scalar>
416 typedef typename NumTraits<Scalar>::Real type;
423 template<
typename OldType,
typename NewType,
typename EnableIf =
void>
427 static inline NewType run(
const OldType& x)
429 return static_cast<NewType
>(x);
435 template<
typename OldType,
typename NewType>
436 struct cast_impl<OldType, NewType,
437 typename std::enable_if_t<
438 !NumTraits<OldType>::IsComplex && NumTraits<NewType>::IsComplex
442 static inline NewType run(
const OldType& x)
444 typedef typename NumTraits<NewType>::Real NewReal;
445 return static_cast<NewType
>(
static_cast<NewReal
>(x));
451 template<
typename OldType,
typename NewType>
453 inline NewType cast(
const OldType& x)
455 return cast_impl<OldType, NewType>::run(x);
462 template<
typename Scalar>
465 EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
468 static inline Scalar run(
const Scalar& x)
470 #if EIGEN_HAS_CXX11_MATH
471 EIGEN_USING_STD(
round);
473 return Scalar(
round(x));
477 #if !EIGEN_HAS_CXX11_MATH
478 #if EIGEN_HAS_C99_MATH
481 struct round_impl<float> {
483 static inline float run(
const float& x)
489 template<
typename Scalar>
490 struct round_using_floor_ceil_impl
492 EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
495 static inline Scalar run(
const Scalar& x)
498 EIGEN_USING_STD(
floor);
499 EIGEN_USING_STD(
ceil);
502 const Scalar limit = Scalar(1ull << (NumTraits<Scalar>::digits() - 1));
503 if (x >= limit || x <= -limit) {
506 return (x > Scalar(0)) ? Scalar(
floor(x + Scalar(0.5))) : Scalar(
ceil(x - Scalar(0.5)));
511 struct round_impl<float> : round_using_floor_ceil_impl<float> {};
514 struct round_impl<double> : round_using_floor_ceil_impl<double> {};
518 template<
typename Scalar>
528 template<
typename Scalar>
530 EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
533 static inline Scalar run(
const Scalar& x)
535 #if EIGEN_HAS_CXX11_MATH
536 EIGEN_USING_STD(
rint);
542 #if !EIGEN_HAS_CXX11_MATH
544 struct rint_impl<double> {
546 static inline double run(
const double& x)
552 struct rint_impl<float> {
554 static inline float run(
const float& x)
561 template<
typename Scalar>
573 #if EIGEN_HAS_CXX11_MATH && (!EIGEN_COMP_MSVC || EIGEN_COMP_MSVC >= 1920)
575 template<
typename Scalar,
576 bool HasStdImpl = NumTraits<Scalar>::IsComplex || is_integral<Scalar>::value
577 || is_same<Scalar, float>::value || is_same<Scalar, double>::value
578 || is_same<Scalar, long double>::value >
579 struct arg_default_impl;
581 template<
typename Scalar>
582 struct arg_default_impl<Scalar, true> {
583 typedef typename NumTraits<Scalar>::Real RealScalar;
585 static inline RealScalar run(
const Scalar& x)
587 #if defined(EIGEN_HIP_DEVICE_COMPILE)
591 EIGEN_USING_STD(
arg);
593 return static_cast<RealScalar
>(
arg(x));
598 template<
typename Scalar>
599 struct arg_default_impl<Scalar, false> {
600 typedef typename NumTraits<Scalar>::Real RealScalar;
602 static inline RealScalar run(
const Scalar& x)
604 return (x < Scalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0);
608 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
609 struct arg_default_impl
611 typedef typename NumTraits<Scalar>::Real RealScalar;
613 static inline RealScalar run(
const Scalar& x)
615 return (x < RealScalar(0)) ? RealScalar(EIGEN_PI) : RealScalar(0);
619 template<
typename Scalar>
620 struct arg_default_impl<Scalar,true>
622 typedef typename NumTraits<Scalar>::Real RealScalar;
624 static inline RealScalar run(
const Scalar& x)
626 EIGEN_USING_STD(
arg);
631 template<
typename Scalar>
struct arg_impl : arg_default_impl<Scalar> {};
633 template<
typename Scalar>
636 typedef typename NumTraits<Scalar>::Real type;
644 namespace std_fallback {
648 template<
typename Scalar>
649 EIGEN_DEVICE_FUNC
inline Scalar
expm1(
const Scalar& x) {
650 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
651 typedef typename NumTraits<Scalar>::Real RealScalar;
653 EIGEN_USING_STD(
exp);
655 if (numext::equal_strict(u, Scalar(1))) {
658 Scalar um1 = u - RealScalar(1);
659 if (numext::equal_strict(um1, Scalar(-1))) {
660 return RealScalar(-1);
663 EIGEN_USING_STD(
log);
664 Scalar logu =
log(u);
665 return numext::equal_strict(u, logu) ? u : (u - RealScalar(1)) * x / logu;
669 template<
typename Scalar>
671 EIGEN_DEVICE_FUNC
static inline Scalar run(
const Scalar& x)
673 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
674 #if EIGEN_HAS_CXX11_MATH
677 using std_fallback::expm1;
683 template<
typename Scalar>
694 template<
typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_log(
const std::complex<T>& z);
696 template<
typename Scalar>
698 EIGEN_DEVICE_FUNC
static inline Scalar run(
const Scalar& x)
700 EIGEN_USING_STD(
log);
701 return static_cast<Scalar
>(
log(x));
705 template<
typename Scalar>
706 struct log_impl<std::complex<Scalar> > {
707 EIGEN_DEVICE_FUNC
static inline std::complex<Scalar> run(
const std::complex<Scalar>& z)
709 return complex_log(z);
717 namespace std_fallback {
720 template<
typename Scalar>
721 EIGEN_DEVICE_FUNC
inline Scalar
log1p(
const Scalar& x) {
722 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
723 typedef typename NumTraits<Scalar>::Real RealScalar;
724 EIGEN_USING_STD(
log);
725 Scalar x1p = RealScalar(1) + x;
726 Scalar log_1p = log_impl<Scalar>::run(x1p);
727 const bool is_small = numext::equal_strict(x1p, Scalar(1));
728 const bool is_inf = numext::equal_strict(x1p, log_1p);
729 return (is_small || is_inf) ? x : x * (log_1p / (x1p - RealScalar(1)));
733 template<
typename Scalar>
735 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
737 EIGEN_DEVICE_FUNC
static inline Scalar run(
const Scalar& x)
739 #if EIGEN_HAS_CXX11_MATH
742 using std_fallback::log1p;
749 template <
typename RealScalar>
750 struct log1p_impl<std::complex<RealScalar> > {
751 EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar)
753 EIGEN_DEVICE_FUNC
static inline std::complex<RealScalar> run(
754 const std::complex<RealScalar>& x) {
755 return std_fallback::log1p(x);
759 template<
typename Scalar>
769 template<typename ScalarX,typename ScalarY, bool IsInteger = NumTraits<ScalarX>::IsInteger&&NumTraits<ScalarY>::IsInteger>
773 typedef typename ScalarBinaryOpTraits<ScalarX,ScalarY,internal::scalar_pow_op<ScalarX,ScalarY> >::ReturnType result_type;
774 static EIGEN_DEVICE_FUNC
inline result_type run(
const ScalarX& x,
const ScalarY& y)
776 EIGEN_USING_STD(pow);
781 template<
typename ScalarX,
typename ScalarY>
782 struct pow_impl<ScalarX,ScalarY, true>
784 typedef ScalarX result_type;
785 static EIGEN_DEVICE_FUNC
inline ScalarX run(ScalarX x, ScalarY y)
788 eigen_assert(!NumTraits<ScalarY>::IsSigned || y >= 0);
805 template<
typename Scalar,
808 struct random_default_impl {};
810 template<
typename Scalar>
811 struct random_impl : random_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
813 template<
typename Scalar>
819 template<
typename Scalar>
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(
const Scalar& x,
const Scalar& y);
820 template<
typename Scalar>
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random();
822 template<
typename Scalar>
823 struct random_default_impl<Scalar, false, false>
825 static inline Scalar run(
const Scalar& x,
const Scalar& y)
827 return x + (y-x) * Scalar(std::rand()) / Scalar(RAND_MAX);
829 static inline Scalar run()
831 return run(Scalar(NumTraits<Scalar>::IsSigned ? -1 : 0), Scalar(1));
836 meta_floor_log2_terminate,
837 meta_floor_log2_move_up,
838 meta_floor_log2_move_down,
839 meta_floor_log2_bogus
842 template<
unsigned int n,
int lower,
int upper>
struct meta_floor_log2_selector
844 enum { middle = (lower + upper) / 2,
845 value = (upper <= lower + 1) ? int(meta_floor_log2_terminate)
846 : (n < (1 << middle)) ? int(meta_floor_log2_move_down)
847 : (n==0) ? int(meta_floor_log2_bogus)
848 : int(meta_floor_log2_move_up)
852 template<
unsigned int n,
854 int upper =
sizeof(
unsigned int) * CHAR_BIT - 1,
855 int selector = meta_floor_log2_selector<n, lower, upper>::value>
856 struct meta_floor_log2 {};
858 template<
unsigned int n,
int lower,
int upper>
859 struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_down>
861 enum { value = meta_floor_log2<n, lower, meta_floor_log2_selector<n, lower, upper>::middle>::value };
864 template<
unsigned int n,
int lower,
int upper>
865 struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_up>
867 enum { value = meta_floor_log2<n, meta_floor_log2_selector<n, lower, upper>::middle, upper>::value };
870 template<
unsigned int n,
int lower,
int upper>
871 struct meta_floor_log2<n, lower, upper, meta_floor_log2_terminate>
873 enum { value = (n >= ((
unsigned int)(1) << (lower+1))) ? lower+1 : lower };
876 template<
unsigned int n,
int lower,
int upper>
877 struct meta_floor_log2<n, lower, upper, meta_floor_log2_bogus>
882 template<
typename Scalar>
883 struct random_default_impl<Scalar, false, true>
885 static inline Scalar run(
const Scalar& x,
const Scalar& y)
890 typedef typename make_unsigned<Scalar>::type ScalarU;
894 typedef std::conditional_t<(ScalarU(-1) > unsigned(-1)), ScalarU,
unsigned> ScalarX;
898 ScalarX range = ScalarX(y) - ScalarX(x);
901 ScalarX multiplier = 1;
902 const unsigned rand_max = RAND_MAX;
903 if (range <= rand_max) divisor = (rand_max + 1) / (range + 1);
904 else multiplier = 1 + range / (rand_max + 1);
907 offset = (unsigned(std::rand()) * multiplier) / divisor;
908 }
while (offset > range);
909 return Scalar(ScalarX(x) + offset);
912 static inline Scalar run()
914 #ifdef EIGEN_MAKING_DOCS
915 return run(Scalar(NumTraits<Scalar>::IsSigned ? -10 : 0), Scalar(10));
917 enum { rand_bits = meta_floor_log2<(
unsigned int)(RAND_MAX)+1>::value,
918 scalar_bits =
sizeof(Scalar) * CHAR_BIT,
919 shift = plain_enum_max(0,
int(rand_bits) - int(scalar_bits)),
920 offset = NumTraits<Scalar>::IsSigned ? (1 << (plain_enum_min(rand_bits, scalar_bits)-1)) : 0
922 return Scalar((std::rand() >> shift) - offset);
927 template<
typename Scalar>
928 struct random_default_impl<Scalar, true, false>
930 static inline Scalar run(
const Scalar& x,
const Scalar& y)
932 return Scalar(random(x.real(), y.real()),
933 random(x.imag(), y.imag()));
935 static inline Scalar run()
937 typedef typename NumTraits<Scalar>::Real RealScalar;
938 return Scalar(random<RealScalar>(), random<RealScalar>());
942 template<
typename Scalar>
943 inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(
const Scalar& x,
const Scalar& y)
945 return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(x, y);
948 template<
typename Scalar>
949 inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random()
951 return EIGEN_MATHFUNC_IMPL(random, Scalar)::run();
957 #if (EIGEN_HAS_CXX11_MATH && !(EIGEN_COMP_GNUC_STRICT && __FINITE_MATH_ONLY__)) || (EIGEN_COMP_MSVC) || (EIGEN_COMP_CLANG)
958 #define EIGEN_USE_STD_FPCLASSIFY 1
960 #define EIGEN_USE_STD_FPCLASSIFY 0
965 std::enable_if_t<internal::is_integral<T>::value,
bool>
966 isnan_impl(
const T&) {
return false; }
970 std::enable_if_t<internal::is_integral<T>::value,
bool>
971 isinf_impl(
const T&) {
return false; }
975 std::enable_if_t<internal::is_integral<T>::value,
bool>
976 isfinite_impl(
const T&) {
return true; }
980 std::enable_if_t<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),
bool>
981 isfinite_impl(
const T& x)
983 #if defined(EIGEN_GPU_COMPILE_PHASE)
985 #elif EIGEN_USE_STD_FPCLASSIFY
987 return isfinite EIGEN_NOT_A_MACRO (x);
989 return x<=NumTraits<T>::highest() && x>=NumTraits<T>::lowest();
995 std::enable_if_t<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),
bool>
996 isinf_impl(
const T& x)
998 #if defined(EIGEN_GPU_COMPILE_PHASE)
1000 #elif EIGEN_USE_STD_FPCLASSIFY
1002 return isinf EIGEN_NOT_A_MACRO (x);
1004 return x>NumTraits<T>::highest() || x<NumTraits<T>::lowest();
1008 template<
typename T>
1010 std::enable_if_t<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),
bool>
1011 isnan_impl(
const T& x)
1013 #if defined(EIGEN_GPU_COMPILE_PHASE)
1014 return (::
isnan)(x);
1015 #elif EIGEN_USE_STD_FPCLASSIFY
1017 return isnan EIGEN_NOT_A_MACRO (x);
1023 #if (!EIGEN_USE_STD_FPCLASSIFY)
1027 template<
typename T> EIGEN_DEVICE_FUNC
bool isinf_msvc_helper(T x)
1029 return _fpclass(x)==_FPCLASS_NINF || _fpclass(x)==_FPCLASS_PINF;
1033 EIGEN_DEVICE_FUNC
inline bool isnan_impl(
const long double& x) {
return _isnan(x)!=0; }
1034 EIGEN_DEVICE_FUNC
inline bool isnan_impl(
const double& x) {
return _isnan(x)!=0; }
1035 EIGEN_DEVICE_FUNC
inline bool isnan_impl(
const float& x) {
return _isnan(x)!=0; }
1037 EIGEN_DEVICE_FUNC
inline bool isinf_impl(
const long double& x) {
return isinf_msvc_helper(x); }
1038 EIGEN_DEVICE_FUNC
inline bool isinf_impl(
const double& x) {
return isinf_msvc_helper(x); }
1039 EIGEN_DEVICE_FUNC
inline bool isinf_impl(
const float& x) {
return isinf_msvc_helper(x); }
1041 #elif (defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ && EIGEN_COMP_GNUC)
1044 #define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((optimize("no-finite-math-only")))
1048 #define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((noinline,optimize("no-finite-math-only")))
1051 template<> EIGEN_TMP_NOOPT_ATTRIB
bool isnan_impl(
const long double& x) {
return __builtin_isnan(x); }
1052 template<> EIGEN_TMP_NOOPT_ATTRIB
bool isnan_impl(
const double& x) {
return __builtin_isnan(x); }
1053 template<> EIGEN_TMP_NOOPT_ATTRIB
bool isnan_impl(
const float& x) {
return __builtin_isnan(x); }
1054 template<> EIGEN_TMP_NOOPT_ATTRIB
bool isinf_impl(
const double& x) {
return __builtin_isinf(x); }
1055 template<> EIGEN_TMP_NOOPT_ATTRIB
bool isinf_impl(
const float& x) {
return __builtin_isinf(x); }
1056 template<> EIGEN_TMP_NOOPT_ATTRIB
bool isinf_impl(
const long double& x) {
return __builtin_isinf(x); }
1058 #undef EIGEN_TMP_NOOPT_ATTRIB
1065 template<
typename T> EIGEN_DEVICE_FUNC
bool isfinite_impl(
const std::complex<T>& x);
1066 template<
typename T> EIGEN_DEVICE_FUNC
bool isnan_impl(
const std::complex<T>& x);
1067 template<
typename T> EIGEN_DEVICE_FUNC
bool isinf_impl(
const std::complex<T>& x);
1069 template<
typename T> T generic_fast_tanh_float(
const T& a_x);
1078 #if (!defined(EIGEN_GPUCC) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
1079 template<
typename T>
1081 EIGEN_ALWAYS_INLINE T mini(
const T& x,
const T& y)
1083 EIGEN_USING_STD(min)
1084 return min EIGEN_NOT_A_MACRO (x,y);
1087 template<
typename T>
1089 EIGEN_ALWAYS_INLINE T maxi(
const T& x,
const T& y)
1091 EIGEN_USING_STD(max)
1092 return max EIGEN_NOT_A_MACRO (x,y);
1095 template<
typename T>
1097 EIGEN_ALWAYS_INLINE T mini(
const T& x,
const T& y)
1099 return y < x ? y : x;
1103 EIGEN_ALWAYS_INLINE
float mini(
const float& x,
const float& y)
1109 EIGEN_ALWAYS_INLINE
double mini(
const double& x,
const double& y)
1115 EIGEN_ALWAYS_INLINE
long double mini(
const long double& x,
const long double& y)
1117 #if defined(EIGEN_HIPCC)
1119 return (x < y) ? x : y;
1125 template<
typename T>
1127 EIGEN_ALWAYS_INLINE T maxi(
const T& x,
const T& y)
1129 return x < y ? y : x;
1133 EIGEN_ALWAYS_INLINE
float maxi(
const float& x,
const float& y)
1139 EIGEN_ALWAYS_INLINE
double maxi(
const double& x,
const double& y)
1145 EIGEN_ALWAYS_INLINE
long double maxi(
const long double& x,
const long double& y)
1147 #if defined(EIGEN_HIPCC)
1149 return (x > y) ? x : y;
1156 #if defined(SYCL_DEVICE_ONLY)
1159 #define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1160 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
1161 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
1162 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
1163 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
1164 #define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1165 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
1166 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
1167 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
1168 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
1169 #define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1170 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
1171 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
1172 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
1173 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
1174 #define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1175 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
1176 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
1177 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
1178 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
1179 #define SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(NAME, FUNC) \
1180 SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1181 SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC)
1182 #define SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(NAME, FUNC) \
1183 SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1184 SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC)
1185 #define SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(NAME, FUNC) \
1186 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
1187 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
1188 #define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(NAME, FUNC) \
1189 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
1190 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
1191 #define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(NAME, FUNC, RET_TYPE) \
1192 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_float) \
1193 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_double)
1195 #define SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
1198 EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE& x) { \
1199 return cl::sycl::FUNC(x); \
1202 #define SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, TYPE) \
1203 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, TYPE, TYPE)
1205 #define SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE1, ARG_TYPE2) \
1208 EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE1& x, const ARG_TYPE2& y) { \
1209 return cl::sycl::FUNC(x, y); \
1212 #define SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
1213 SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE, ARG_TYPE)
1215 #define SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, TYPE) \
1216 SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, TYPE, TYPE)
1218 SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(mini, min)
1219 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(mini, fmin)
1220 SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(maxi, max)
1221 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(maxi, fmax)
1226 template<
typename Scalar>
1228 inline EIGEN_MATHFUNC_RETVAL(
real, Scalar)
real(
const Scalar& x)
1230 return EIGEN_MATHFUNC_IMPL(
real, Scalar)::run(x);
1233 template<
typename Scalar>
1235 inline internal::add_const_on_value_type_t< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) > real_ref(
const Scalar& x)
1237 return internal::real_ref_impl<Scalar>::run(x);
1240 template<
typename Scalar>
1242 inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x)
1244 return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x);
1247 template<
typename Scalar>
1249 inline EIGEN_MATHFUNC_RETVAL(
imag, Scalar)
imag(
const Scalar& x)
1251 return EIGEN_MATHFUNC_IMPL(
imag, Scalar)::run(x);
1254 template<
typename Scalar>
1256 inline EIGEN_MATHFUNC_RETVAL(
arg, Scalar)
arg(
const Scalar& x)
1258 return EIGEN_MATHFUNC_IMPL(
arg, Scalar)::run(x);
1261 template<
typename Scalar>
1263 inline internal::add_const_on_value_type_t< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) > imag_ref(
const Scalar& x)
1265 return internal::imag_ref_impl<Scalar>::run(x);
1268 template<
typename Scalar>
1270 inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x)
1272 return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x);
1275 template<
typename Scalar>
1277 inline EIGEN_MATHFUNC_RETVAL(
conj, Scalar)
conj(
const Scalar& x)
1279 return EIGEN_MATHFUNC_IMPL(
conj, Scalar)::run(x);
1282 template<
typename Scalar>
1284 inline EIGEN_MATHFUNC_RETVAL(
abs2, Scalar)
abs2(
const Scalar& x)
1286 return EIGEN_MATHFUNC_IMPL(
abs2, Scalar)::run(x);
1290 inline bool abs2(
bool x) {
return x; }
1292 template<
typename T>
1294 EIGEN_ALWAYS_INLINE T absdiff(
const T& x,
const T& y)
1296 return x > y ? x - y : y - x;
1300 EIGEN_ALWAYS_INLINE
float absdiff(
const float& x,
const float& y)
1302 return fabsf(x - y);
1306 EIGEN_ALWAYS_INLINE
double absdiff(
const double& x,
const double& y)
1311 #if !defined(EIGEN_GPUCC)
1315 EIGEN_ALWAYS_INLINE
long double absdiff(
const long double& x,
const long double& y) {
1316 return fabsl(x - y);
1320 template<
typename Scalar>
1322 inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(
const Scalar& x)
1324 return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x);
1327 template<
typename Scalar>
1329 inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(
const Scalar& x,
const Scalar& y)
1331 return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y);
1334 #if defined(SYCL_DEVICE_ONLY)
1335 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(hypot, hypot)
1338 template<
typename Scalar>
1340 inline EIGEN_MATHFUNC_RETVAL(
log1p, Scalar)
log1p(
const Scalar& x)
1342 return EIGEN_MATHFUNC_IMPL(
log1p, Scalar)::run(x);
1345 #if defined(SYCL_DEVICE_ONLY)
1346 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
log1p,
log1p)
1349 #if defined(EIGEN_GPUCC)
1350 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1351 float log1p(
const float &x) { return ::log1pf(x); }
1353 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1354 double log1p(
const double &x) { return ::log1p(x); }
1357 template<
typename ScalarX,
typename ScalarY>
1359 inline typename internal::pow_impl<ScalarX,ScalarY>::result_type pow(
const ScalarX& x,
const ScalarY& y)
1361 return internal::pow_impl<ScalarX,ScalarY>::run(x, y);
1364 #if defined(SYCL_DEVICE_ONLY)
1365 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(pow, pow)
1368 template<
typename T> EIGEN_DEVICE_FUNC bool (
isnan) (
const T &x) {
return internal::isnan_impl(x); }
1369 template<
typename T> EIGEN_DEVICE_FUNC bool (
isinf) (
const T &x) {
return internal::isinf_impl(x); }
1370 template<
typename T> EIGEN_DEVICE_FUNC bool (
isfinite)(
const T &x) {
return internal::isfinite_impl(x); }
1372 #if defined(SYCL_DEVICE_ONLY)
1373 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(
isnan,
isnan,
bool)
1374 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(
isinf,
isinf,
bool)
1375 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(
isfinite,
isfinite,
bool)
1378 template<
typename Scalar>
1380 inline EIGEN_MATHFUNC_RETVAL(
rint, Scalar)
rint(
const Scalar& x)
1382 return EIGEN_MATHFUNC_IMPL(
rint, Scalar)::run(x);
1385 template<
typename Scalar>
1387 inline EIGEN_MATHFUNC_RETVAL(
round, Scalar)
round(
const Scalar& x)
1389 return EIGEN_MATHFUNC_IMPL(
round, Scalar)::run(x);
1392 #if defined(SYCL_DEVICE_ONLY)
1393 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
round,
round)
1396 template<
typename T>
1398 T (
floor)(
const T& x)
1400 EIGEN_USING_STD(
floor)
1404 #if defined(SYCL_DEVICE_ONLY)
1405 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
floor,
floor)
1408 #if defined(EIGEN_GPUCC)
1409 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1410 float floor(
const float &x) { return ::floorf(x); }
1412 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1413 double floor(
const double &x) { return ::floor(x); }
1416 template<
typename T>
1418 T (
ceil)(
const T& x)
1420 EIGEN_USING_STD(
ceil);
1424 #if defined(SYCL_DEVICE_ONLY)
1425 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
ceil,
ceil)
1428 #if defined(EIGEN_GPUCC)
1429 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1430 float ceil(
const float &x) { return ::ceilf(x); }
1432 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1433 double ceil(
const double &x) { return ::ceil(x); }
1439 inline int log2(
int x)
1443 static const int table[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
1449 return table[(v * 0x07C4ACDDU) >> 27];
1461 template<
typename Scalar>
1463 EIGEN_ALWAYS_INLINE EIGEN_MATHFUNC_RETVAL(
sqrt, Scalar)
sqrt(
const Scalar& x)
1465 return EIGEN_MATHFUNC_IMPL(
sqrt, Scalar)::run(x);
1470 EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC
1471 bool sqrt<bool>(
const bool &x) {
return x; }
1473 #if defined(SYCL_DEVICE_ONLY)
1474 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
sqrt,
sqrt)
1478 template<
typename T>
1479 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1482 return internal::rsqrt_impl<T>::run(x);
1485 template<
typename T>
1486 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1488 return internal::log_impl<T>::run(x);
1491 #if defined(SYCL_DEVICE_ONLY)
1492 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
log,
log)
1496 #if defined(EIGEN_GPUCC)
1497 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1498 float log(
const float &x) { return ::logf(x); }
1500 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1501 double log(
const double &x) { return ::log(x); }
1504 template<
typename T>
1505 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1506 std::enable_if_t<NumTraits<T>::IsSigned || NumTraits<T>::IsComplex,
typename NumTraits<T>::Real>
1508 EIGEN_USING_STD(
abs);
1512 template<
typename T>
1513 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1514 std::enable_if_t<!(NumTraits<T>::IsSigned || NumTraits<T>::IsComplex),
typename NumTraits<T>::Real>
1519 #if defined(SYCL_DEVICE_ONLY)
1520 SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(
abs,
abs)
1521 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
abs, fabs)
1524 #if defined(EIGEN_GPUCC)
1525 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1526 float abs(
const float &x) { return ::fabsf(x); }
1528 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1529 double abs(
const double &x) { return ::fabs(x); }
1531 template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1532 float abs(
const std::complex<float>& x) {
1533 return ::hypotf(x.real(), x.imag());
1536 template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1537 double abs(
const std::complex<double>& x) {
1538 return ::hypot(x.real(), x.imag());
1542 template<
typename T>
1543 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1545 EIGEN_USING_STD(
exp);
1549 #if defined(SYCL_DEVICE_ONLY)
1550 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
exp,
exp)
1553 #if defined(EIGEN_GPUCC)
1554 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1555 float exp(
const float &x) { return ::expf(x); }
1557 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1558 double exp(
const double &x) { return ::exp(x); }
1560 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1561 std::complex<float>
exp(
const std::complex<float>& x) {
1562 float com = ::expf(x.real());
1563 float res_real = com * ::cosf(x.imag());
1564 float res_imag = com * ::sinf(x.imag());
1565 return std::complex<float>(res_real, res_imag);
1568 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1569 std::complex<double>
exp(
const std::complex<double>& x) {
1570 double com =
::exp(x.real());
1571 double res_real = com *
::cos(x.imag());
1572 double res_imag = com *
::sin(x.imag());
1573 return std::complex<double>(res_real, res_imag);
1577 template<
typename Scalar>
1579 inline EIGEN_MATHFUNC_RETVAL(
expm1, Scalar)
expm1(
const Scalar& x)
1581 return EIGEN_MATHFUNC_IMPL(
expm1, Scalar)::run(x);
1584 #if defined(SYCL_DEVICE_ONLY)
1585 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
expm1,
expm1)
1588 #if defined(EIGEN_GPUCC)
1589 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1590 float expm1(
const float &x) { return ::expm1f(x); }
1592 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1593 double expm1(
const double &x) { return ::expm1(x); }
1596 template<
typename T>
1597 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1599 EIGEN_USING_STD(
cos);
1603 #if defined(SYCL_DEVICE_ONLY)
1604 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
cos,
cos)
1607 #if defined(EIGEN_GPUCC)
1608 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1609 float cos(
const float &x) { return ::cosf(x); }
1611 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1612 double cos(
const double &x) { return ::cos(x); }
1615 template<
typename T>
1616 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1618 EIGEN_USING_STD(
sin);
1622 #if defined(SYCL_DEVICE_ONLY)
1623 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
sin,
sin)
1626 #if defined(EIGEN_GPUCC)
1627 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1628 float sin(
const float &x) { return ::sinf(x); }
1630 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1631 double sin(
const double &x) { return ::sin(x); }
1634 template<
typename T>
1635 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1637 EIGEN_USING_STD(
tan);
1641 #if defined(SYCL_DEVICE_ONLY)
1642 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
tan,
tan)
1645 #if defined(EIGEN_GPUCC)
1646 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1647 float tan(
const float &x) { return ::tanf(x); }
1649 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1650 double tan(
const double &x) { return ::tan(x); }
1653 template<
typename T>
1654 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1655 T
acos(
const T &x) {
1656 EIGEN_USING_STD(
acos);
1660 #if EIGEN_HAS_CXX11_MATH
1661 template<
typename T>
1662 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1663 T
acosh(
const T &x) {
1664 EIGEN_USING_STD(
acosh);
1665 return static_cast<T
>(
acosh(x));
1669 #if defined(SYCL_DEVICE_ONLY)
1670 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
acos,
acos)
1671 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
acosh,
acosh)
1674 #if defined(EIGEN_GPUCC)
1675 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1676 float acos(
const float &x) { return ::acosf(x); }
1678 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1679 double acos(
const double &x) { return ::acos(x); }
1682 template<
typename T>
1683 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1684 T
asin(
const T &x) {
1685 EIGEN_USING_STD(
asin);
1689 #if EIGEN_HAS_CXX11_MATH
1690 template<
typename T>
1691 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1692 T
asinh(
const T &x) {
1693 EIGEN_USING_STD(
asinh);
1694 return static_cast<T
>(
asinh(x));
1698 #if defined(SYCL_DEVICE_ONLY)
1699 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
asin,
asin)
1700 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
asinh,
asinh)
1703 #if defined(EIGEN_GPUCC)
1704 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1705 float asin(
const float &x) { return ::asinf(x); }
1707 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1708 double asin(
const double &x) { return ::asin(x); }
1711 template<
typename T>
1712 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1713 T
atan(
const T &x) {
1714 EIGEN_USING_STD(
atan);
1715 return static_cast<T
>(
atan(x));
1718 #if EIGEN_HAS_CXX11_MATH
1719 template<
typename T>
1720 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1721 T
atanh(
const T &x) {
1722 EIGEN_USING_STD(
atanh);
1723 return static_cast<T
>(
atanh(x));
1727 #if defined(SYCL_DEVICE_ONLY)
1728 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
atan,
atan)
1729 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
atanh,
atanh)
1732 #if defined(EIGEN_GPUCC)
1733 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1734 float atan(
const float &x) { return ::atanf(x); }
1736 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1737 double atan(
const double &x) { return ::atan(x); }
1741 template<
typename T>
1742 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1743 T
cosh(
const T &x) {
1744 EIGEN_USING_STD(
cosh);
1745 return static_cast<T
>(
cosh(x));
1748 #if defined(SYCL_DEVICE_ONLY)
1749 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
cosh,
cosh)
1752 #if defined(EIGEN_GPUCC)
1753 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1754 float cosh(
const float &x) { return ::coshf(x); }
1756 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1757 double cosh(
const double &x) { return ::cosh(x); }
1760 template<
typename T>
1761 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1762 T
sinh(
const T &x) {
1763 EIGEN_USING_STD(
sinh);
1764 return static_cast<T
>(
sinh(x));
1767 #if defined(SYCL_DEVICE_ONLY)
1768 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
sinh,
sinh)
1771 #if defined(EIGEN_GPUCC)
1772 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1773 float sinh(
const float &x) { return ::sinhf(x); }
1775 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1776 double sinh(
const double &x) { return ::sinh(x); }
1779 template<
typename T>
1780 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1781 T
tanh(
const T &x) {
1782 EIGEN_USING_STD(
tanh);
1786 #if (!defined(EIGEN_GPUCC)) && EIGEN_FAST_MATH && !defined(SYCL_DEVICE_ONLY)
1787 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1788 float tanh(
float x) {
return internal::generic_fast_tanh_float(x); }
1791 #if defined(SYCL_DEVICE_ONLY)
1792 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
tanh,
tanh)
1795 #if defined(EIGEN_GPUCC)
1796 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1797 float tanh(
const float &x) { return ::tanhf(x); }
1799 template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1800 double tanh(
const double &x) { return ::tanh(x); }
1803 template <
typename T>
1804 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1805 T fmod(
const T& a,
const T& b) {
1806 EIGEN_USING_STD(fmod);
1810 #if defined(SYCL_DEVICE_ONLY)
1811 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(fmod, fmod)
1814 #if defined(EIGEN_GPUCC)
1816 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1817 float fmod(
const float& a,
const float& b) {
1818 return ::fmodf(a, b);
1822 EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1823 double fmod(
const double& a,
const double& b) {
1824 return ::fmod(a, b);
1828 #if defined(SYCL_DEVICE_ONLY)
1829 #undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY
1830 #undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY
1831 #undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY
1832 #undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
1833 #undef SYCL_SPECIALIZE_INTEGER_TYPES_BINARY
1834 #undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
1835 #undef SYCL_SPECIALIZE_FLOATING_TYPES_BINARY
1836 #undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY
1837 #undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE
1838 #undef SYCL_SPECIALIZE_GEN_UNARY_FUNC
1839 #undef SYCL_SPECIALIZE_UNARY_FUNC
1840 #undef SYCL_SPECIALIZE_GEN1_BINARY_FUNC
1841 #undef SYCL_SPECIALIZE_GEN2_BINARY_FUNC
1842 #undef SYCL_SPECIALIZE_BINARY_FUNC
1847 namespace internal {
1849 template<
typename T>
1850 EIGEN_DEVICE_FUNC
bool isfinite_impl(
const std::complex<T>& x)
1852 return (numext::isfinite)(numext::real(x)) && (numext::isfinite)(numext::imag(x));
1855 template<
typename T>
1856 EIGEN_DEVICE_FUNC
bool isnan_impl(
const std::complex<T>& x)
1858 return (numext::isnan)(numext::real(x)) || (numext::isnan)(numext::imag(x));
1861 template<
typename T>
1862 EIGEN_DEVICE_FUNC
bool isinf_impl(
const std::complex<T>& x)
1864 return ((numext::isinf)(numext::real(x)) || (numext::isinf)(numext::imag(x))) && (!(numext::isnan)(x));
1871 template<
typename Scalar,
1874 struct scalar_fuzzy_default_impl {};
1876 template<
typename Scalar>
1877 struct scalar_fuzzy_default_impl<Scalar, false, false>
1879 typedef typename NumTraits<Scalar>::Real RealScalar;
1880 template<
typename OtherScalar> EIGEN_DEVICE_FUNC
1881 static inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
const RealScalar& prec)
1883 return numext::abs(x) <= numext::abs(y) * prec;
1886 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
1888 return numext::abs(x - y) <= numext::mini(numext::abs(x), numext::abs(y)) * prec;
1891 static inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
1893 return x <= y || isApprox(x, y, prec);
1897 template<
typename Scalar>
1898 struct scalar_fuzzy_default_impl<Scalar, false, true>
1900 typedef typename NumTraits<Scalar>::Real RealScalar;
1901 template<
typename OtherScalar> EIGEN_DEVICE_FUNC
1902 static inline bool isMuchSmallerThan(
const Scalar& x,
const Scalar&,
const RealScalar&)
1904 return x == Scalar(0);
1907 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar&)
1912 static inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
const RealScalar&)
1918 template<
typename Scalar>
1919 struct scalar_fuzzy_default_impl<Scalar, true, false>
1921 typedef typename NumTraits<Scalar>::Real RealScalar;
1922 template<
typename OtherScalar> EIGEN_DEVICE_FUNC
1923 static inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
const RealScalar& prec)
1925 return numext::abs2(x) <= numext::abs2(y) * prec * prec;
1928 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
1930 return numext::abs2(x - y) <= numext::mini(numext::abs2(x), numext::abs2(y)) * prec * prec;
1934 template<
typename Scalar>
1935 struct scalar_fuzzy_impl : scalar_fuzzy_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
1937 template<
typename Scalar,
typename OtherScalar> EIGEN_DEVICE_FUNC
1938 inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
1939 const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
1941 return scalar_fuzzy_impl<Scalar>::template isMuchSmallerThan<OtherScalar>(x, y, precision);
1944 template<
typename Scalar> EIGEN_DEVICE_FUNC
1945 inline bool isApprox(
const Scalar& x,
const Scalar& y,
1946 const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
1948 return scalar_fuzzy_impl<Scalar>::isApprox(x, y, precision);
1951 template<
typename Scalar> EIGEN_DEVICE_FUNC
1952 inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
1953 const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
1955 return scalar_fuzzy_impl<Scalar>::isApproxOrLessThan(x, y, precision);
1962 template<>
struct random_impl<bool>
1964 static inline bool run()
1966 return random<int>(0,1)==0 ? false :
true;
1969 static inline bool run(
const bool& a,
const bool& b)
1971 return random<int>(a, b)==0 ? false :
true;
1975 template<>
struct scalar_fuzzy_impl<bool>
1977 typedef bool RealScalar;
1979 template<
typename OtherScalar> EIGEN_DEVICE_FUNC
1980 static inline bool isMuchSmallerThan(
const bool& x,
const bool&,
const bool&)
1986 static inline bool isApprox(
bool x,
bool y,
bool)
1992 static inline bool isApproxOrLessThan(
const bool& x,
const bool& y,
const bool&)
2002 namespace internal {
2005 template <
typename RealScalar>
2006 struct expm1_impl<std::complex<RealScalar> > {
2007 EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar)
2009 EIGEN_DEVICE_FUNC
static inline std::complex<RealScalar> run(
2010 const std::complex<RealScalar>& x) {
2011 RealScalar xr = x.real();
2012 RealScalar xi = x.imag();
2022 RealScalar erm1 = numext::expm1<RealScalar>(xr);
2023 RealScalar er = erm1 + RealScalar(1.);
2024 RealScalar sin2 = numext::sin(xi / RealScalar(2.));
2026 RealScalar s = numext::sin(xi);
2027 RealScalar real_part = erm1 - RealScalar(2.) * er * sin2;
2028 return std::complex<RealScalar>(real_part, er * s);
2032 template<
typename T>
2035 static EIGEN_ALWAYS_INLINE T run(
const T& x) {
2036 return T(1)/numext::sqrt(x);
2040 #if defined(EIGEN_GPU_COMPILE_PHASE)
2041 template<
typename T>
2042 struct conj_impl<std::complex<T>, true>
2045 static inline std::complex<T> run(
const std::complex<T>& x)
2047 return std::complex<T>(numext::real(x), -numext::imag(x));
Namespace containing all symbols from the Eigen library.
Definition: Core:139
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_tanh_op< typename Derived::Scalar >, const Derived > tanh(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_rint_op< typename Derived::Scalar >, const Derived > rint(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_imag_op< typename Derived::Scalar >, const Derived > imag(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_isinf_op< typename Derived::Scalar >, const Derived > isinf(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_atan_op< typename Derived::Scalar >, const Derived > atan(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_cosh_op< typename Derived::Scalar >, const Derived > cosh(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_tan_op< typename Derived::Scalar >, const Derived > tan(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_acos_op< typename Derived::Scalar >, const Derived > acos(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_atanh_op< typename Derived::Scalar >, const Derived > atanh(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs2_op< typename Derived::Scalar >, const Derived > abs2(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_rsqrt_op< typename Derived::Scalar >, const Derived > rsqrt(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_asin_op< typename Derived::Scalar >, const Derived > asin(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_asinh_op< typename Derived::Scalar >, const Derived > asinh(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_acosh_op< typename Derived::Scalar >, const Derived > acosh(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_isnan_op< typename Derived::Scalar >, const Derived > isnan(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_arg_op< typename Derived::Scalar >, const Derived > arg(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_ceil_op< typename Derived::Scalar >, const Derived > ceil(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_conjugate_op< typename Derived::Scalar >, const Derived > conj(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_isfinite_op< typename Derived::Scalar >, const Derived > isfinite(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_floor_op< typename Derived::Scalar >, const Derived > floor(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_log1p_op< typename Derived::Scalar >, const Derived > log1p(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_real_op< typename Derived::Scalar >, const Derived > real(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_cos_op< typename Derived::Scalar >, const Derived > cos(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_log2_op< typename Derived::Scalar >, const Derived > log2(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_round_op< typename Derived::Scalar >, const Derived > round(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_abs_op< typename Derived::Scalar >, const Derived > abs(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_exp_op< typename Derived::Scalar >, const Derived > exp(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sin_op< typename Derived::Scalar >, const Derived > sin(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_expm1_op< typename Derived::Scalar >, const Derived > expm1(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_log_op< typename Derived::Scalar >, const Derived > log(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sinh_op< typename Derived::Scalar >, const Derived > sinh(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)