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
24#if EIGEN_OS_WINCE && EIGEN_COMP_MSVC && EIGEN_COMP_MSVC<=1500
25long abs(
long x) {
return (labs(x)); }
26double abs(
double x) {
return (fabs(x)); }
27float abs(
float x) {
return (fabsf(x)); }
28long double abs(
long double x) {
return (fabsl(x)); }
53template<
typename T,
typename dummy =
void>
54struct global_math_functions_filtering_base
59template<
typename T>
struct always_void {
typedef void type; };
62struct global_math_functions_filtering_base
64 typename always_void<typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl>::type
67 typedef typename T::Eigen_BaseClassForSpecializationOfGlobalMathFuncImpl type;
70#define EIGEN_MATHFUNC_IMPL(func, scalar) Eigen::internal::func##_impl<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>
71#define EIGEN_MATHFUNC_RETVAL(func, scalar) typename Eigen::internal::func##_retval<typename Eigen::internal::global_math_functions_filtering_base<scalar>::type>::type
77template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
78struct real_default_impl
80 typedef typename NumTraits<Scalar>::Real RealScalar;
82 static inline RealScalar run(
const Scalar& x)
88template<
typename Scalar>
89struct real_default_impl<Scalar,true>
91 typedef typename NumTraits<Scalar>::Real RealScalar;
93 static inline RealScalar run(
const Scalar& x)
100template<
typename Scalar>
struct real_impl : real_default_impl<Scalar> {};
102#if defined(EIGEN_GPU_COMPILE_PHASE)
104struct real_impl<std::complex<T> >
106 typedef T RealScalar;
108 static inline T run(
const std::complex<T>& x)
115template<
typename Scalar>
118 typedef typename NumTraits<Scalar>::Real type;
125template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
126struct imag_default_impl
128 typedef typename NumTraits<Scalar>::Real RealScalar;
130 static inline RealScalar run(
const Scalar&)
132 return RealScalar(0);
136template<
typename Scalar>
137struct imag_default_impl<Scalar,true>
139 typedef typename NumTraits<Scalar>::Real RealScalar;
141 static inline RealScalar run(
const Scalar& x)
148template<
typename Scalar>
struct imag_impl : imag_default_impl<Scalar> {};
150#if defined(EIGEN_GPU_COMPILE_PHASE)
152struct imag_impl<std::complex<T> >
154 typedef T RealScalar;
156 static inline T run(
const std::complex<T>& x)
163template<
typename Scalar>
166 typedef typename NumTraits<Scalar>::Real type;
173template<
typename Scalar>
176 typedef typename NumTraits<Scalar>::Real RealScalar;
178 static inline RealScalar& run(Scalar& x)
180 return reinterpret_cast<RealScalar*
>(&x)[0];
183 static inline const RealScalar& run(
const Scalar& x)
185 return reinterpret_cast<const RealScalar*
>(&x)[0];
189template<
typename Scalar>
190struct real_ref_retval
192 typedef typename NumTraits<Scalar>::Real & type;
199template<
typename Scalar,
bool IsComplex>
200struct imag_ref_default_impl
202 typedef typename NumTraits<Scalar>::Real RealScalar;
204 static inline RealScalar& run(Scalar& x)
206 return reinterpret_cast<RealScalar*
>(&x)[1];
209 static inline const RealScalar& run(
const Scalar& x)
211 return reinterpret_cast<RealScalar*
>(&x)[1];
215template<
typename Scalar>
216struct imag_ref_default_impl<Scalar, false>
218 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
219 static inline Scalar run(Scalar&)
223 EIGEN_DEVICE_FUNC EIGEN_CONSTEXPR
224 static inline const Scalar run(
const Scalar&)
230template<
typename Scalar>
231struct imag_ref_impl : imag_ref_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
233template<
typename Scalar>
234struct imag_ref_retval
236 typedef typename NumTraits<Scalar>::Real & type;
243template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
244struct conj_default_impl
247 static inline Scalar run(
const Scalar& x)
253template<
typename Scalar>
254struct conj_default_impl<Scalar,true>
257 static inline Scalar run(
const Scalar& x)
264template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
265struct conj_impl : conj_default_impl<Scalar, IsComplex> {};
267template<
typename Scalar>
277template<
typename Scalar,
bool IsComplex>
278struct abs2_impl_default
280 typedef typename NumTraits<Scalar>::Real RealScalar;
282 static inline RealScalar run(
const Scalar& x)
288template<
typename Scalar>
289struct abs2_impl_default<Scalar, true>
291 typedef typename NumTraits<Scalar>::Real RealScalar;
293 static inline RealScalar run(
const Scalar& x)
295 return x.real()*x.real() + x.imag()*x.imag();
299template<
typename Scalar>
302 typedef typename NumTraits<Scalar>::Real RealScalar;
304 static inline RealScalar run(
const Scalar& x)
306 return abs2_impl_default<Scalar,NumTraits<Scalar>::IsComplex>::run(x);
310template<
typename Scalar>
313 typedef typename NumTraits<Scalar>::Real type;
320template<
typename Scalar>
324 static EIGEN_ALWAYS_INLINE Scalar run(
const Scalar& x)
326 EIGEN_USING_STD(sqrt);
332template<
typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_sqrt(
const std::complex<T>& a_x);
337struct sqrt_impl<std::complex<T> >
340 static EIGEN_ALWAYS_INLINE std::complex<T> run(
const std::complex<T>& x)
342 return complex_sqrt<T>(x);
346template<
typename Scalar>
357template<
typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_rsqrt(
const std::complex<T>& a_x);
360struct rsqrt_impl<std::complex<T> >
363 static EIGEN_ALWAYS_INLINE std::complex<T> run(
const std::complex<T>& x)
365 return complex_rsqrt<T>(x);
369template<
typename Scalar>
379template<
typename Scalar,
bool IsComplex>
380struct norm1_default_impl;
382template<
typename Scalar>
383struct norm1_default_impl<Scalar,true>
385 typedef typename NumTraits<Scalar>::Real RealScalar;
387 static inline RealScalar run(
const Scalar& x)
389 EIGEN_USING_STD(abs);
390 return abs(x.real()) + abs(x.imag());
394template<
typename Scalar>
395struct norm1_default_impl<Scalar, false>
398 static inline Scalar run(
const Scalar& x)
400 EIGEN_USING_STD(abs);
405template<
typename Scalar>
406struct norm1_impl : norm1_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
408template<
typename Scalar>
411 typedef typename NumTraits<Scalar>::Real type;
418template<
typename Scalar>
struct hypot_impl;
420template<
typename Scalar>
423 typedef typename NumTraits<Scalar>::Real type;
430template<
typename OldType,
typename NewType,
typename EnableIf =
void>
434 static inline NewType run(
const OldType& x)
436 return static_cast<NewType
>(x);
442template<
typename OldType,
typename NewType>
443struct cast_impl<OldType, NewType,
444 typename internal::enable_if<
445 !NumTraits<OldType>::IsComplex && NumTraits<NewType>::IsComplex
449 static inline NewType run(
const OldType& x)
451 typedef typename NumTraits<NewType>::Real NewReal;
452 return static_cast<NewType
>(
static_cast<NewReal
>(x));
458template<
typename OldType,
typename NewType>
460inline NewType cast(
const OldType& x)
462 return cast_impl<OldType, NewType>::run(x);
469template<
typename Scalar>
473 static inline Scalar run(
const Scalar& x)
475 EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
476#if EIGEN_HAS_CXX11_MATH
477 EIGEN_USING_STD(round);
479 return Scalar(round(x));
483#if !EIGEN_HAS_CXX11_MATH
484#if EIGEN_HAS_C99_MATH
487struct round_impl<float> {
489 static inline float run(
const float& x)
495template<
typename Scalar>
496struct round_using_floor_ceil_impl
499 static inline Scalar run(
const Scalar& x)
501 EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
503 EIGEN_USING_STD(floor);
504 EIGEN_USING_STD(ceil);
507 const Scalar limit = Scalar(1ull << (NumTraits<Scalar>::digits() - 1));
508 if (x >= limit || x <= -limit) {
511 return (x > Scalar(0)) ? Scalar(floor(x + Scalar(0.5))) : Scalar(ceil(x - Scalar(0.5)));
516struct round_impl<float> : round_using_floor_ceil_impl<float> {};
519struct round_impl<double> : round_using_floor_ceil_impl<double> {};
523template<
typename Scalar>
533template<
typename Scalar>
536 static inline Scalar run(
const Scalar& x)
538 EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
539#if EIGEN_HAS_CXX11_MATH
540 EIGEN_USING_STD(rint);
546#if !EIGEN_HAS_CXX11_MATH
548struct rint_impl<double> {
550 static inline double run(
const double& x)
556struct rint_impl<float> {
558 static inline float run(
const float& x)
565template<
typename Scalar>
577#if EIGEN_HAS_CXX11_MATH && (!EIGEN_COMP_MSVC || EIGEN_COMP_MSVC >= 1920)
579template<
typename Scalar,
580 bool HasStdImpl = NumTraits<Scalar>::IsComplex || is_integral<Scalar>::value
581 || is_same<Scalar, float>::value || is_same<Scalar, double>::value
582 || is_same<Scalar, long double>::value >
583struct arg_default_impl;
585template<
typename Scalar>
586struct arg_default_impl<Scalar, true> {
587 typedef typename NumTraits<Scalar>::Real RealScalar;
589 static inline RealScalar run(
const Scalar& x)
593 return static_cast<RealScalar
>(
arg(x));
598template<
typename Scalar>
599struct 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);
608template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
609struct 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);
619template<
typename Scalar>
620struct 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);
631template<
typename Scalar>
struct arg_impl : arg_default_impl<Scalar> {};
633template<
typename Scalar>
636 typedef typename NumTraits<Scalar>::Real type;
644namespace 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;
669template<
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;
683template<
typename Scalar>
694template<
typename T> EIGEN_DEVICE_FUNC std::complex<T> complex_log(
const std::complex<T>& z);
696template<
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));
705template<
typename Scalar>
706struct 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);
717namespace 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)));
733template<
typename Scalar>
735 EIGEN_DEVICE_FUNC
static inline Scalar run(
const Scalar& x)
737 EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
738 #if EIGEN_HAS_CXX11_MATH
741 using std_fallback::log1p;
748template <
typename RealScalar>
749struct log1p_impl<std::complex<RealScalar> > {
750 EIGEN_DEVICE_FUNC
static inline std::complex<RealScalar> run(
751 const std::complex<RealScalar>& x) {
752 EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar)
753 return std_fallback::log1p(x);
757template<
typename Scalar>
767template<typename ScalarX,typename ScalarY, bool IsInteger = NumTraits<ScalarX>::IsInteger&&NumTraits<ScalarY>::IsInteger>
771 typedef typename ScalarBinaryOpTraits<ScalarX,ScalarY,internal::scalar_pow_op<ScalarX,ScalarY> >::ReturnType result_type;
772 static EIGEN_DEVICE_FUNC
inline result_type run(
const ScalarX& x,
const ScalarY& y)
774 EIGEN_USING_STD(
pow);
779template<
typename ScalarX,
typename ScalarY>
780struct pow_impl<ScalarX,ScalarY, true>
782 typedef ScalarX result_type;
783 static EIGEN_DEVICE_FUNC
inline ScalarX run(ScalarX x, ScalarY y)
786 eigen_assert(!NumTraits<ScalarY>::IsSigned || y >= 0);
803template<
typename Scalar,
806struct random_default_impl {};
808template<
typename Scalar>
809struct random_impl : random_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
811template<
typename Scalar>
817template<
typename Scalar>
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(
const Scalar& x,
const Scalar& y);
818template<
typename Scalar>
inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random();
820template<
typename Scalar>
821struct random_default_impl<Scalar, false, false>
823 static inline Scalar run(
const Scalar& x,
const Scalar& y)
825 return x + (y-x) * Scalar(std::rand()) / Scalar(RAND_MAX);
827 static inline Scalar run()
829 return run(Scalar(NumTraits<Scalar>::IsSigned ? -1 : 0), Scalar(1));
834 meta_floor_log2_terminate,
835 meta_floor_log2_move_up,
836 meta_floor_log2_move_down,
837 meta_floor_log2_bogus
840template<
unsigned int n,
int lower,
int upper>
struct meta_floor_log2_selector
842 enum { middle = (lower + upper) / 2,
843 value = (upper <= lower + 1) ? int(meta_floor_log2_terminate)
844 : (n < (1 << middle)) ? int(meta_floor_log2_move_down)
845 : (n==0) ? int(meta_floor_log2_bogus)
846 : int(meta_floor_log2_move_up)
850template<
unsigned int n,
852 int upper =
sizeof(
unsigned int) * CHAR_BIT - 1,
853 int selector = meta_floor_log2_selector<n, lower, upper>::value>
854struct meta_floor_log2 {};
856template<
unsigned int n,
int lower,
int upper>
857struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_down>
859 enum { value = meta_floor_log2<n, lower, meta_floor_log2_selector<n, lower, upper>::middle>::value };
862template<
unsigned int n,
int lower,
int upper>
863struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_up>
865 enum { value = meta_floor_log2<n, meta_floor_log2_selector<n, lower, upper>::middle, upper>::value };
868template<
unsigned int n,
int lower,
int upper>
869struct meta_floor_log2<n, lower, upper, meta_floor_log2_terminate>
871 enum { value = (n >= ((
unsigned int)(1) << (lower+1))) ? lower+1 : lower };
874template<
unsigned int n,
int lower,
int upper>
875struct meta_floor_log2<n, lower, upper, meta_floor_log2_bogus>
880template <
typename BitsType,
typename EnableIf =
void>
881struct count_bits_impl {
882 static EIGEN_DEVICE_FUNC
inline int clz(BitsType bits) {
884 is_integral<BitsType>::value && !NumTraits<BitsType>::IsSigned,
885 THIS_TYPE_IS_NOT_SUPPORTED);
886 int n = CHAR_BIT *
sizeof(BitsType);
888 while (bits > 0 && shift > 0) {
889 BitsType y = bits >> shift;
902 static EIGEN_DEVICE_FUNC
inline int ctz(BitsType bits) {
904 is_integral<BitsType>::value && !NumTraits<BitsType>::IsSigned,
905 THIS_TYPE_IS_NOT_SUPPORTED);
906 int n = CHAR_BIT *
sizeof(BitsType);
908 while (bits > 0 && shift > 0) {
909 BitsType y = bits << shift;
924template <
typename BitsType>
925EIGEN_DEVICE_FUNC
inline int clz(BitsType bits) {
926 return count_bits_impl<BitsType>::clz(bits);
930template <
typename BitsType>
931EIGEN_DEVICE_FUNC
inline int ctz(BitsType bits) {
932 return count_bits_impl<BitsType>::ctz(bits);
935#if EIGEN_COMP_GNUC || EIGEN_COMP_CLANG
937template <
typename BitsType>
938struct count_bits_impl<BitsType, typename enable_if<sizeof(BitsType) <=
sizeof(
unsigned int)>::type> {
939 static const int kNumBits =
static_cast<int>(
sizeof(BitsType) * CHAR_BIT);
940 static EIGEN_DEVICE_FUNC
inline int clz(BitsType bits) {
941 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
942 static const int kLeadingBitsOffset = (
sizeof(
unsigned int) -
sizeof(BitsType)) * CHAR_BIT;
943 return bits == 0 ? kNumBits : __builtin_clz(
static_cast<unsigned int>(bits)) - kLeadingBitsOffset;
946 static EIGEN_DEVICE_FUNC
inline int ctz(BitsType bits) {
947 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
948 return bits == 0 ? kNumBits : __builtin_ctz(
static_cast<unsigned int>(bits));
952template <
typename BitsType>
953struct count_bits_impl<
954 BitsType, typename enable_if<sizeof(unsigned int) < sizeof(BitsType) &&
sizeof(BitsType) <=
sizeof(
unsigned long)>::type> {
955 static const int kNumBits =
static_cast<int>(
sizeof(BitsType) * CHAR_BIT);
956 static EIGEN_DEVICE_FUNC
inline int clz(BitsType bits) {
957 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
958 static const int kLeadingBitsOffset = (
sizeof(
unsigned long) -
sizeof(BitsType)) * CHAR_BIT;
959 return bits == 0 ? kNumBits : __builtin_clzl(
static_cast<unsigned long>(bits)) - kLeadingBitsOffset;
962 static EIGEN_DEVICE_FUNC
inline int ctz(BitsType bits) {
963 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
964 return bits == 0 ? kNumBits : __builtin_ctzl(
static_cast<unsigned long>(bits));
968template <
typename BitsType>
969struct count_bits_impl<BitsType, typename enable_if<sizeof(unsigned long) < sizeof(BitsType) &&
970 sizeof(BitsType) <=
sizeof(
unsigned long long)>::type> {
971 static const int kNumBits =
static_cast<int>(
sizeof(BitsType) * CHAR_BIT);
972 static EIGEN_DEVICE_FUNC
inline int clz(BitsType bits) {
973 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
974 static const int kLeadingBitsOffset = (
sizeof(
unsigned long long) -
sizeof(BitsType)) * CHAR_BIT;
975 return bits == 0 ? kNumBits : __builtin_clzll(
static_cast<unsigned long long>(bits)) - kLeadingBitsOffset;
978 static EIGEN_DEVICE_FUNC
inline int ctz(BitsType bits) {
979 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
980 return bits == 0 ? kNumBits : __builtin_ctzll(
static_cast<unsigned long long>(bits));
986template <
typename BitsType>
987struct count_bits_impl<BitsType, typename enable_if<sizeof(BitsType) <=
sizeof(
unsigned long)>::type> {
988 static const int kNumBits =
static_cast<int>(
sizeof(BitsType) * CHAR_BIT);
989 static EIGEN_DEVICE_FUNC
inline int clz(BitsType bits) {
990 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
992 _BitScanReverse(&out,
static_cast<unsigned long>(bits));
993 return bits == 0 ? kNumBits : (kNumBits - 1) -
static_cast<int>(out);
996 static EIGEN_DEVICE_FUNC
inline int ctz(BitsType bits) {
997 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
999 _BitScanForward(&out,
static_cast<unsigned long>(bits));
1000 return bits == 0 ? kNumBits :
static_cast<int>(out);
1006template <
typename BitsType>
1007struct count_bits_impl<
1008 BitsType, typename enable_if<sizeof(unsigned long) < sizeof(BitsType) &&
sizeof(BitsType) <=
sizeof(__int64)>::type> {
1009 static const int kNumBits =
static_cast<int>(
sizeof(BitsType) * CHAR_BIT);
1010 static EIGEN_DEVICE_FUNC
inline int clz(BitsType bits) {
1011 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
1013 _BitScanReverse64(&out,
static_cast<unsigned __int64
>(bits));
1014 return bits == 0 ? kNumBits : (kNumBits - 1) -
static_cast<int>(out);
1017 static EIGEN_DEVICE_FUNC
inline int ctz(BitsType bits) {
1018 EIGEN_STATIC_ASSERT(is_integral<BitsType>::value, THIS_TYPE_IS_NOT_SUPPORTED);
1020 _BitScanForward64(&out,
static_cast<unsigned __int64
>(bits));
1021 return bits == 0 ? kNumBits :
static_cast<int>(out);
1029template <
typename Scalar>
1030struct random_default_impl<Scalar, false, true> {
1031 static inline Scalar run(
const Scalar& x,
const Scalar& y) {
1032 if (y <= x)
return x;
1034 typedef typename make_unsigned<Scalar>::type ScalarU;
1038 typedef typename conditional<(ScalarU(-1) > unsigned(-1)), ScalarU,
unsigned>::type ScalarX;
1042 ScalarX range = ScalarX(y) - ScalarX(x);
1044 ScalarX divisor = 1;
1045 ScalarX multiplier = 1;
1046 const unsigned rand_max = RAND_MAX;
1047 if (range <= rand_max) divisor = (rand_max + 1) / (range + 1);
1048 else multiplier = 1 + range / (rand_max + 1);
1051 offset = (unsigned(std::rand()) * multiplier) / divisor;
1052 }
while (offset > range);
1053 return Scalar(ScalarX(x) + offset);
1056 static inline Scalar run()
1058#ifdef EIGEN_MAKING_DOCS
1059 return run(Scalar(NumTraits<Scalar>::IsSigned ? -10 : 0), Scalar(10));
1061 enum { rand_bits = meta_floor_log2<(
unsigned int)(RAND_MAX)+1>::value,
1062 scalar_bits =
sizeof(Scalar) * CHAR_BIT,
1063 shift = EIGEN_PLAIN_ENUM_MAX(0,
int(rand_bits) -
int(scalar_bits)),
1064 offset = NumTraits<Scalar>::IsSigned ? (1 << (EIGEN_PLAIN_ENUM_MIN(rand_bits,scalar_bits)-1)) : 0
1066 return Scalar((std::rand() >> shift) - offset);
1071template<
typename Scalar>
1072struct random_default_impl<Scalar, true, false>
1074 static inline Scalar run(
const Scalar& x,
const Scalar& y)
1076 return Scalar(random(x.real(), y.real()),
1077 random(x.imag(), y.imag()));
1079 static inline Scalar run()
1081 typedef typename NumTraits<Scalar>::Real RealScalar;
1082 return Scalar(random<RealScalar>(), random<RealScalar>());
1086template<
typename Scalar>
1087inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random(
const Scalar& x,
const Scalar& y)
1089 return EIGEN_MATHFUNC_IMPL(random, Scalar)::run(x, y);
1092template<
typename Scalar>
1093inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random()
1095 return EIGEN_MATHFUNC_IMPL(random, Scalar)::run();
1101#if (EIGEN_HAS_CXX11_MATH && !(EIGEN_COMP_GNUC_STRICT && __FINITE_MATH_ONLY__)) || (EIGEN_COMP_MSVC>=1800) || (EIGEN_COMP_CLANG)
1102#define EIGEN_USE_STD_FPCLASSIFY 1
1104#define EIGEN_USE_STD_FPCLASSIFY 0
1109typename internal::enable_if<internal::is_integral<T>::value,
bool>::type
1110isnan_impl(
const T&) {
return false; }
1114typename internal::enable_if<internal::is_integral<T>::value,
bool>::type
1115isinf_impl(
const T&) {
return false; }
1119typename internal::enable_if<internal::is_integral<T>::value,
bool>::type
1120isfinite_impl(
const T&) {
return true; }
1124typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),
bool>::type
1125isfinite_impl(
const T& x)
1127 #if defined(EIGEN_GPU_COMPILE_PHASE)
1128 return (::isfinite)(x);
1129 #elif EIGEN_USE_STD_FPCLASSIFY
1130 using std::isfinite;
1131 return isfinite EIGEN_NOT_A_MACRO (x);
1133 return x<=NumTraits<T>::highest() && x>=NumTraits<T>::lowest();
1139typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),
bool>::type
1140isinf_impl(
const T& x)
1142 #if defined(EIGEN_GPU_COMPILE_PHASE)
1143 return (::isinf)(x);
1144 #elif EIGEN_USE_STD_FPCLASSIFY
1146 return isinf EIGEN_NOT_A_MACRO (x);
1148 return x>NumTraits<T>::highest() || x<NumTraits<T>::lowest();
1154typename internal::enable_if<(!internal::is_integral<T>::value)&&(!NumTraits<T>::IsComplex),
bool>::type
1155isnan_impl(
const T& x)
1157 #if defined(EIGEN_GPU_COMPILE_PHASE)
1158 return (::isnan)(x);
1159 #elif EIGEN_USE_STD_FPCLASSIFY
1161 return isnan EIGEN_NOT_A_MACRO (x);
1167#if (!EIGEN_USE_STD_FPCLASSIFY)
1171template<
typename T> EIGEN_DEVICE_FUNC
bool isinf_msvc_helper(T x)
1173 return _fpclass(x)==_FPCLASS_NINF || _fpclass(x)==_FPCLASS_PINF;
1177#ifndef EIGEN_GPU_COMPILE_PHASE
1178EIGEN_DEVICE_FUNC
inline bool isnan_impl(
const long double& x) {
return _isnan(x)!=0; }
1180EIGEN_DEVICE_FUNC
inline bool isnan_impl(
const double& x) {
return _isnan(x)!=0; }
1181EIGEN_DEVICE_FUNC
inline bool isnan_impl(
const float& x) {
return _isnan(x)!=0; }
1183#ifndef EIGEN_GPU_COMPILE_PHASE
1184EIGEN_DEVICE_FUNC
inline bool isinf_impl(
const long double& x) {
return isinf_msvc_helper(x); }
1186EIGEN_DEVICE_FUNC
inline bool isinf_impl(
const double& x) {
return isinf_msvc_helper(x); }
1187EIGEN_DEVICE_FUNC
inline bool isinf_impl(
const float& x) {
return isinf_msvc_helper(x); }
1189#elif (defined __FINITE_MATH_ONLY__ && __FINITE_MATH_ONLY__ && EIGEN_COMP_GNUC)
1191#if EIGEN_GNUC_AT_LEAST(5,0)
1192 #define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((optimize("no-finite-math-only")))
1196 #define EIGEN_TMP_NOOPT_ATTRIB EIGEN_DEVICE_FUNC inline __attribute__((noinline,optimize("no-finite-math-only")))
1199#ifndef EIGEN_GPU_COMPILE_PHASE
1200template<> EIGEN_TMP_NOOPT_ATTRIB
bool isnan_impl(
const long double& x) {
return __builtin_isnan(x); }
1202template<> EIGEN_TMP_NOOPT_ATTRIB
bool isnan_impl(
const double& x) {
return __builtin_isnan(x); }
1203template<> EIGEN_TMP_NOOPT_ATTRIB
bool isnan_impl(
const float& x) {
return __builtin_isnan(x); }
1204template<> EIGEN_TMP_NOOPT_ATTRIB
bool isinf_impl(
const double& x) {
return __builtin_isinf(x); }
1205template<> EIGEN_TMP_NOOPT_ATTRIB
bool isinf_impl(
const float& x) {
return __builtin_isinf(x); }
1206#ifndef EIGEN_GPU_COMPILE_PHASE
1207template<> EIGEN_TMP_NOOPT_ATTRIB
bool isinf_impl(
const long double& x) {
return __builtin_isinf(x); }
1210#undef EIGEN_TMP_NOOPT_ATTRIB
1217template<
typename T> EIGEN_DEVICE_FUNC
bool isfinite_impl(
const std::complex<T>& x);
1218template<
typename T> EIGEN_DEVICE_FUNC
bool isnan_impl(
const std::complex<T>& x);
1219template<
typename T> EIGEN_DEVICE_FUNC
bool isinf_impl(
const std::complex<T>& x);
1221template<
typename T> T generic_fast_tanh_float(
const T& a_x);
1230#if (!defined(EIGEN_GPUCC) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
1233EIGEN_ALWAYS_INLINE T mini(
const T& x,
const T& y)
1235 EIGEN_USING_STD(min)
1236 return min EIGEN_NOT_A_MACRO (x,y);
1241EIGEN_ALWAYS_INLINE T maxi(
const T& x,
const T& y)
1243 EIGEN_USING_STD(max)
1244 return max EIGEN_NOT_A_MACRO (x,y);
1249EIGEN_ALWAYS_INLINE T mini(
const T& x,
const T& y)
1251 return y < x ? y : x;
1255EIGEN_ALWAYS_INLINE
float mini(
const float& x,
const float& y)
1261EIGEN_ALWAYS_INLINE
double mini(
const double& x,
const double& y)
1266#ifndef EIGEN_GPU_COMPILE_PHASE
1269EIGEN_ALWAYS_INLINE
long double mini(
const long double& x,
const long double& y)
1271#if defined(EIGEN_HIPCC)
1273 return (x < y) ? x : y;
1282EIGEN_ALWAYS_INLINE T maxi(
const T& x,
const T& y)
1284 return x < y ? y : x;
1288EIGEN_ALWAYS_INLINE
float maxi(
const float& x,
const float& y)
1294EIGEN_ALWAYS_INLINE
double maxi(
const double& x,
const double& y)
1298#ifndef EIGEN_GPU_COMPILE_PHASE
1301EIGEN_ALWAYS_INLINE
long double maxi(
const long double& x,
const long double& y)
1303#if defined(EIGEN_HIPCC)
1305 return (x > y) ? x : y;
1313#if defined(SYCL_DEVICE_ONLY)
1316#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1317 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
1318 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
1319 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
1320 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
1321#define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1322 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
1323 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
1324 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
1325 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
1326#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1327 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
1328 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
1329 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
1330 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
1331#define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1332 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
1333 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
1334 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
1335 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
1336#define SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(NAME, FUNC) \
1337 SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1338 SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC)
1339#define SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(NAME, FUNC) \
1340 SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1341 SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC)
1342#define SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(NAME, FUNC) \
1343 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
1344 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
1345#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(NAME, FUNC) \
1346 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
1347 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
1348#define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(NAME, FUNC, RET_TYPE) \
1349 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_float) \
1350 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_double)
1352#define SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
1355 EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE& x) { \
1356 return cl::sycl::FUNC(x); \
1359#define SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, TYPE) \
1360 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, TYPE, TYPE)
1362#define SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE1, ARG_TYPE2) \
1365 EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE1& x, const ARG_TYPE2& y) { \
1366 return cl::sycl::FUNC(x, y); \
1369#define SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
1370 SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE, ARG_TYPE)
1372#define SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, TYPE) \
1373 SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, TYPE, TYPE)
1375SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(mini, min)
1376SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(mini, fmin)
1377SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(maxi, max)
1378SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(maxi, fmax)
1383template<
typename Scalar>
1385inline EIGEN_MATHFUNC_RETVAL(real, Scalar)
real(
const Scalar& x)
1387 return EIGEN_MATHFUNC_IMPL(real, Scalar)::run(x);
1390template<
typename Scalar>
1392inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) >::type real_ref(
const Scalar& x)
1394 return internal::real_ref_impl<Scalar>::run(x);
1397template<
typename Scalar>
1399inline EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) real_ref(Scalar& x)
1401 return EIGEN_MATHFUNC_IMPL(real_ref, Scalar)::run(x);
1404template<
typename Scalar>
1406inline EIGEN_MATHFUNC_RETVAL(imag, Scalar)
imag(
const Scalar& x)
1408 return EIGEN_MATHFUNC_IMPL(imag, Scalar)::run(x);
1411template<
typename Scalar>
1413inline EIGEN_MATHFUNC_RETVAL(arg, Scalar)
arg(
const Scalar& x)
1415 return EIGEN_MATHFUNC_IMPL(arg, Scalar)::run(x);
1418template<
typename Scalar>
1420inline typename internal::add_const_on_value_type< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) >::type imag_ref(
const Scalar& x)
1422 return internal::imag_ref_impl<Scalar>::run(x);
1425template<
typename Scalar>
1427inline EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) imag_ref(Scalar& x)
1429 return EIGEN_MATHFUNC_IMPL(imag_ref, Scalar)::run(x);
1432template<
typename Scalar>
1434inline EIGEN_MATHFUNC_RETVAL(conj, Scalar)
conj(
const Scalar& x)
1436 return EIGEN_MATHFUNC_IMPL(conj, Scalar)::run(x);
1439template<
typename Scalar>
1441inline EIGEN_MATHFUNC_RETVAL(abs2, Scalar)
abs2(
const Scalar& x)
1443 return EIGEN_MATHFUNC_IMPL(abs2, Scalar)::run(x);
1447inline bool abs2(
bool x) {
return x; }
1451EIGEN_ALWAYS_INLINE T absdiff(
const T& x,
const T& y)
1453 return x > y ? x - y : y - x;
1457EIGEN_ALWAYS_INLINE
float absdiff(
const float& x,
const float& y)
1459 return fabsf(x - y);
1463EIGEN_ALWAYS_INLINE
double absdiff(
const double& x,
const double& y)
1469#ifndef EIGEN_GPU_COMPILE_PHASE
1472EIGEN_ALWAYS_INLINE
long double absdiff(
const long double& x,
const long double& y) {
1473 return fabsl(x - y);
1477template<
typename Scalar>
1479inline EIGEN_MATHFUNC_RETVAL(norm1, Scalar) norm1(
const Scalar& x)
1481 return EIGEN_MATHFUNC_IMPL(norm1, Scalar)::run(x);
1484template<
typename Scalar>
1486inline EIGEN_MATHFUNC_RETVAL(hypot, Scalar) hypot(
const Scalar& x,
const Scalar& y)
1488 return EIGEN_MATHFUNC_IMPL(hypot, Scalar)::run(x, y);
1491#if defined(SYCL_DEVICE_ONLY)
1492 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(hypot, hypot)
1495template<
typename Scalar>
1497inline EIGEN_MATHFUNC_RETVAL(log1p, Scalar) log1p(
const Scalar& x)
1499 return EIGEN_MATHFUNC_IMPL(log1p, Scalar)::run(x);
1502#if defined(SYCL_DEVICE_ONLY)
1503SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log1p, log1p)
1506#if defined(EIGEN_GPUCC)
1507template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1508float log1p(
const float &x) { return ::log1pf(x); }
1510template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1511double log1p(
const double &x) { return ::log1p(x); }
1514template<
typename ScalarX,
typename ScalarY>
1516inline typename internal::pow_impl<ScalarX,ScalarY>::result_type pow(
const ScalarX& x,
const ScalarY& y)
1518 return internal::pow_impl<ScalarX,ScalarY>::run(x, y);
1521#if defined(SYCL_DEVICE_ONLY)
1522SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(pow, pow)
1525template<
typename T> EIGEN_DEVICE_FUNC bool (isnan) (
const T &x) {
return internal::isnan_impl(x); }
1526template<
typename T> EIGEN_DEVICE_FUNC bool (isinf) (
const T &x) {
return internal::isinf_impl(x); }
1527template<
typename T> EIGEN_DEVICE_FUNC bool (isfinite)(
const T &x) {
return internal::isfinite_impl(x); }
1529#if defined(SYCL_DEVICE_ONLY)
1530SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isnan, isnan,
bool)
1531SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isinf, isinf,
bool)
1532SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(isfinite, isfinite,
bool)
1535template<
typename Scalar>
1537inline EIGEN_MATHFUNC_RETVAL(rint, Scalar) rint(
const Scalar& x)
1539 return EIGEN_MATHFUNC_IMPL(rint, Scalar)::run(x);
1542template<
typename Scalar>
1544inline EIGEN_MATHFUNC_RETVAL(round, Scalar) round(
const Scalar& x)
1546 return EIGEN_MATHFUNC_IMPL(round, Scalar)::run(x);
1549#if defined(SYCL_DEVICE_ONLY)
1550SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(round, round)
1555T (floor)(
const T& x)
1557 EIGEN_USING_STD(floor)
1561#if defined(SYCL_DEVICE_ONLY)
1562SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(floor, floor)
1565#if defined(EIGEN_GPUCC)
1566template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1567float floor(
const float &x) { return ::floorf(x); }
1569template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1570double floor(
const double &x) { return ::floor(x); }
1577 EIGEN_USING_STD(ceil);
1581#if defined(SYCL_DEVICE_ONLY)
1582SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(ceil, ceil)
1585#if defined(EIGEN_GPUCC)
1586template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1587float ceil(
const float &x) { return ::ceilf(x); }
1589template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1590double ceil(
const double &x) { return ::ceil(x); }
1596inline int log2(
int x)
1600 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 };
1606 return table[(v * 0x07C4ACDDU) >> 27];
1618template<
typename Scalar>
1620EIGEN_ALWAYS_INLINE EIGEN_MATHFUNC_RETVAL(sqrt, Scalar) sqrt(
const Scalar& x)
1622 return EIGEN_MATHFUNC_IMPL(sqrt, Scalar)::run(x);
1627EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_DEVICE_FUNC
1628bool sqrt<bool>(
const bool &x) {
return x; }
1630#if defined(SYCL_DEVICE_ONLY)
1631SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sqrt, sqrt)
1636EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1639 return internal::rsqrt_impl<T>::run(x);
1643EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1645 return internal::log_impl<T>::run(x);
1648#if defined(SYCL_DEVICE_ONLY)
1649SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(log, log)
1653#if defined(EIGEN_GPUCC)
1654template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1655float log(
const float &x) { return ::logf(x); }
1657template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1658double log(
const double &x) { return ::log(x); }
1662EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1663typename internal::enable_if<NumTraits<T>::IsSigned || NumTraits<T>::IsComplex,
typename NumTraits<T>::Real>::type
1665 EIGEN_USING_STD(abs);
1670EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1671typename internal::enable_if<!(NumTraits<T>::IsSigned || NumTraits<T>::IsComplex),
typename NumTraits<T>::Real>::type
1676#if defined(SYCL_DEVICE_ONLY)
1677SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(abs, abs)
1678SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(abs, fabs)
1681#if defined(EIGEN_GPUCC)
1682template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1683float abs(
const float &x) { return ::fabsf(x); }
1685template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1686double abs(
const double &x) { return ::fabs(x); }
1688template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1689float abs(
const std::complex<float>& x) {
1690 return ::hypotf(x.real(), x.imag());
1693template <> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1694double abs(
const std::complex<double>& x) {
1695 return ::hypot(x.real(), x.imag());
1700EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1702 EIGEN_USING_STD(exp);
1706#if defined(SYCL_DEVICE_ONLY)
1707SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(exp, exp)
1710#if defined(EIGEN_GPUCC)
1711template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1712float exp(
const float &x) { return ::expf(x); }
1714template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1715double exp(
const double &x) { return ::exp(x); }
1717template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1718std::complex<float> exp(
const std::complex<float>& x) {
1719 float com = ::expf(x.real());
1720 float res_real = com * ::cosf(x.imag());
1721 float res_imag = com * ::sinf(x.imag());
1722 return std::complex<float>(res_real, res_imag);
1725template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1726std::complex<double> exp(
const std::complex<double>& x) {
1727 double com = ::exp(x.real());
1728 double res_real = com * ::cos(x.imag());
1729 double res_imag = com * ::sin(x.imag());
1730 return std::complex<double>(res_real, res_imag);
1734template<
typename Scalar>
1736inline EIGEN_MATHFUNC_RETVAL(expm1, Scalar) expm1(
const Scalar& x)
1738 return EIGEN_MATHFUNC_IMPL(expm1, Scalar)::run(x);
1741#if defined(SYCL_DEVICE_ONLY)
1742SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(expm1, expm1)
1745#if defined(EIGEN_GPUCC)
1746template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1747float expm1(
const float &x) { return ::expm1f(x); }
1749template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1750double expm1(
const double &x) { return ::expm1(x); }
1754EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1756 EIGEN_USING_STD(cos);
1760#if defined(SYCL_DEVICE_ONLY)
1761SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cos,cos)
1764#if defined(EIGEN_GPUCC)
1765template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1766float cos(
const float &x) { return ::cosf(x); }
1768template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1769double cos(
const double &x) { return ::cos(x); }
1773EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1775 EIGEN_USING_STD(sin);
1779#if defined(SYCL_DEVICE_ONLY)
1780SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sin, sin)
1783#if defined(EIGEN_GPUCC)
1784template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1785float sin(
const float &x) { return ::sinf(x); }
1787template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1788double sin(
const double &x) { return ::sin(x); }
1792EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1794 EIGEN_USING_STD(tan);
1798#if defined(SYCL_DEVICE_ONLY)
1799SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tan, tan)
1802#if defined(EIGEN_GPUCC)
1803template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1804float tan(
const float &x) { return ::tanf(x); }
1806template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1807double tan(
const double &x) { return ::tan(x); }
1811EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1813 EIGEN_USING_STD(acos);
1817#if EIGEN_HAS_CXX11_MATH
1819EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1820T acosh(
const T &x) {
1821 EIGEN_USING_STD(acosh);
1822 return static_cast<T
>(acosh(x));
1826#if defined(SYCL_DEVICE_ONLY)
1827SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acos, acos)
1828SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acosh, acosh)
1831#if defined(EIGEN_GPUCC)
1832template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1833float acos(
const float &x) { return ::acosf(x); }
1835template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1836double acos(
const double &x) { return ::acos(x); }
1840EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1842 EIGEN_USING_STD(asin);
1846#if EIGEN_HAS_CXX11_MATH
1848EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1849T asinh(
const T &x) {
1850 EIGEN_USING_STD(asinh);
1851 return static_cast<T
>(asinh(x));
1855#if defined(SYCL_DEVICE_ONLY)
1856SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asin, asin)
1857SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asinh, asinh)
1860#if defined(EIGEN_GPUCC)
1861template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1862float asin(
const float &x) { return ::asinf(x); }
1864template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1865double asin(
const double &x) { return ::asin(x); }
1869EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1871 EIGEN_USING_STD(atan);
1872 return static_cast<T
>(atan(x));
1875#if EIGEN_HAS_CXX11_MATH
1877EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1878T atanh(
const T &x) {
1879 EIGEN_USING_STD(atanh);
1880 return static_cast<T
>(atanh(x));
1884#if defined(SYCL_DEVICE_ONLY)
1885SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atan, atan)
1886SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atanh, atanh)
1889#if defined(EIGEN_GPUCC)
1890template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1891float atan(
const float &x) { return ::atanf(x); }
1893template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1894double atan(
const double &x) { return ::atan(x); }
1899EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1901 EIGEN_USING_STD(cosh);
1902 return static_cast<T
>(cosh(x));
1905#if defined(SYCL_DEVICE_ONLY)
1906SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(cosh, cosh)
1909#if defined(EIGEN_GPUCC)
1910template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1911float cosh(
const float &x) { return ::coshf(x); }
1913template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1914double cosh(
const double &x) { return ::cosh(x); }
1918EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1920 EIGEN_USING_STD(sinh);
1921 return static_cast<T
>(sinh(x));
1924#if defined(SYCL_DEVICE_ONLY)
1925SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(sinh, sinh)
1928#if defined(EIGEN_GPUCC)
1929template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1930float sinh(
const float &x) { return ::sinhf(x); }
1932template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1933double sinh(
const double &x) { return ::sinh(x); }
1937EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1939 EIGEN_USING_STD(tanh);
1943#if (!defined(EIGEN_GPUCC)) && EIGEN_FAST_MATH && !defined(SYCL_DEVICE_ONLY)
1944EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1945float tanh(
float x) {
return internal::generic_fast_tanh_float(x); }
1948#if defined(SYCL_DEVICE_ONLY)
1949SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(tanh, tanh)
1952#if defined(EIGEN_GPUCC)
1953template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1954float tanh(
const float &x) { return ::tanhf(x); }
1956template<> EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1957double tanh(
const double &x) { return ::tanh(x); }
1960template <
typename T>
1961EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1962T fmod(
const T& a,
const T& b) {
1963 EIGEN_USING_STD(fmod);
1967#if defined(SYCL_DEVICE_ONLY)
1968SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(fmod, fmod)
1971#if defined(EIGEN_GPUCC)
1973EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1974float fmod(
const float& a,
const float& b) {
1975 return ::fmodf(a, b);
1979EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
1980double fmod(
const double& a,
const double& b) {
1981 return ::fmod(a, b);
1985#if defined(SYCL_DEVICE_ONLY)
1986#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY
1987#undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY
1988#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY
1989#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
1990#undef SYCL_SPECIALIZE_INTEGER_TYPES_BINARY
1991#undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
1992#undef SYCL_SPECIALIZE_FLOATING_TYPES_BINARY
1993#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY
1994#undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE
1995#undef SYCL_SPECIALIZE_GEN_UNARY_FUNC
1996#undef SYCL_SPECIALIZE_UNARY_FUNC
1997#undef SYCL_SPECIALIZE_GEN1_BINARY_FUNC
1998#undef SYCL_SPECIALIZE_GEN2_BINARY_FUNC
1999#undef SYCL_SPECIALIZE_BINARY_FUNC
2007EIGEN_DEVICE_FUNC
bool isfinite_impl(
const std::complex<T>& x)
2009 return (numext::isfinite)(numext::real(x)) && (numext::isfinite)(numext::imag(x));
2013EIGEN_DEVICE_FUNC
bool isnan_impl(
const std::complex<T>& x)
2015 return (numext::isnan)(numext::real(x)) || (numext::isnan)(numext::imag(x));
2019EIGEN_DEVICE_FUNC
bool isinf_impl(
const std::complex<T>& x)
2021 return ((numext::isinf)(numext::real(x)) || (numext::isinf)(numext::imag(x))) && (!(numext::isnan)(x));
2028template<
typename Scalar,
2031struct scalar_fuzzy_default_impl {};
2033template<
typename Scalar>
2034struct scalar_fuzzy_default_impl<Scalar, false, false>
2036 typedef typename NumTraits<Scalar>::Real RealScalar;
2037 template<
typename OtherScalar> EIGEN_DEVICE_FUNC
2038 static inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
const RealScalar& prec)
2040 return numext::abs(x) <= numext::abs(y) * prec;
2043 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
2045 return numext::abs(x - y) <= numext::mini(numext::abs(x), numext::abs(y)) * prec;
2048 static inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
2050 return x <= y || isApprox(x, y, prec);
2054template<
typename Scalar>
2055struct scalar_fuzzy_default_impl<Scalar, false, true>
2057 typedef typename NumTraits<Scalar>::Real RealScalar;
2058 template<
typename OtherScalar> EIGEN_DEVICE_FUNC
2059 static inline bool isMuchSmallerThan(
const Scalar& x,
const Scalar&,
const RealScalar&)
2061 return x == Scalar(0);
2064 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar&)
2069 static inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
const RealScalar&)
2075template<
typename Scalar>
2076struct scalar_fuzzy_default_impl<Scalar, true, false>
2078 typedef typename NumTraits<Scalar>::Real RealScalar;
2079 template<
typename OtherScalar> EIGEN_DEVICE_FUNC
2080 static inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
const RealScalar& prec)
2082 return numext::abs2(x) <= numext::abs2(y) * prec * prec;
2085 static inline bool isApprox(
const Scalar& x,
const Scalar& y,
const RealScalar& prec)
2087 return numext::abs2(x - y) <= numext::mini(numext::abs2(x), numext::abs2(y)) * prec * prec;
2091template<
typename Scalar>
2092struct scalar_fuzzy_impl : scalar_fuzzy_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
2094template<
typename Scalar,
typename OtherScalar> EIGEN_DEVICE_FUNC
2095inline bool isMuchSmallerThan(
const Scalar& x,
const OtherScalar& y,
2096 const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
2098 return scalar_fuzzy_impl<Scalar>::template isMuchSmallerThan<OtherScalar>(x, y, precision);
2101template<
typename Scalar> EIGEN_DEVICE_FUNC
2102inline bool isApprox(
const Scalar& x,
const Scalar& y,
2103 const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
2105 return scalar_fuzzy_impl<Scalar>::isApprox(x, y, precision);
2108template<
typename Scalar> EIGEN_DEVICE_FUNC
2109inline bool isApproxOrLessThan(
const Scalar& x,
const Scalar& y,
2110 const typename NumTraits<Scalar>::Real &precision = NumTraits<Scalar>::dummy_precision())
2112 return scalar_fuzzy_impl<Scalar>::isApproxOrLessThan(x, y, precision);
2119template<>
struct random_impl<bool>
2121 static inline bool run()
2123 return random<int>(0,1)==0 ? false :
true;
2126 static inline bool run(
const bool& a,
const bool& b)
2128 return random<int>(a, b)==0 ? false :
true;
2132template<>
struct scalar_fuzzy_impl<bool>
2134 typedef bool RealScalar;
2136 template<
typename OtherScalar> EIGEN_DEVICE_FUNC
2137 static inline bool isMuchSmallerThan(
const bool& x,
const bool&,
const bool&)
2143 static inline bool isApprox(
bool x,
bool y,
bool)
2149 static inline bool isApproxOrLessThan(
const bool& x,
const bool& y,
const bool&)
2162template <
typename RealScalar>
2163struct expm1_impl<std::complex<RealScalar> > {
2164 EIGEN_DEVICE_FUNC
static inline std::complex<RealScalar> run(
2165 const std::complex<RealScalar>& x) {
2166 EIGEN_STATIC_ASSERT_NON_INTEGER(RealScalar)
2167 RealScalar xr = x.real();
2168 RealScalar xi = x.imag();
2178 RealScalar erm1 = numext::expm1<RealScalar>(xr);
2179 RealScalar er = erm1 + RealScalar(1.);
2180 RealScalar sin2 = numext::sin(xi / RealScalar(2.));
2182 RealScalar s = numext::sin(xi);
2183 RealScalar real_part = erm1 - RealScalar(2.) * er * sin2;
2184 return std::complex<RealScalar>(real_part, er * s);
2191 static EIGEN_ALWAYS_INLINE T run(
const T& x) {
2192 return T(1)/numext::sqrt(x);
2196#if defined(EIGEN_GPU_COMPILE_PHASE)
2198struct conj_impl<std::complex<T>, true>
2201 static inline std::complex<T> run(
const std::complex<T>& x)
2203 return std::complex<T>(numext::real(x), -numext::imag(x));
const CwiseBinaryOp< internal::scalar_pow_op< Derived::Scalar, ScalarExponent >, Derived, Constant< ScalarExponent > > pow(const Eigen::ArrayBase< Derived > &x, const ScalarExponent &exponent)
Namespace containing all symbols from the Eigen library.
Definition B01_Experimental.dox:1
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_conjugate_op< typename Derived::Scalar >, const Derived > conj(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_abs_op< typename Derived::Scalar >, const Derived > abs(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_imag_op< typename Derived::Scalar >, const Derived > imag(const Eigen::ArrayBase< Derived > &x)
const Eigen::CwiseUnaryOp< Eigen::internal::scalar_arg_op< typename Derived::Scalar >, const Derived > arg(const Eigen::ArrayBase< Derived > &x)