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
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
75 static inline RealScalar run(
const Scalar&
x)
81 template<
typename Scalar>
82 struct real_default_impl<Scalar,true>
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>
118 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
119 struct imag_default_impl
123 static inline RealScalar run(
const Scalar&)
125 return RealScalar(0);
129 template<
typename Scalar>
130 struct imag_default_impl<Scalar,true>
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>
166 template<
typename Scalar>
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
192 template<
typename Scalar,
bool IsComplex>
193 struct imag_ref_default_impl
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>
212 static inline Scalar run(Scalar&)
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
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
275 static inline RealScalar run(
const Scalar&
x)
281 template<
typename Scalar>
282 struct abs2_impl_default<Scalar, true>
286 static inline RealScalar run(
const Scalar&
x)
288 return x.real()*
x.real() +
x.imag()*
x.imag();
292 template<
typename Scalar>
297 static inline RealScalar run(
const Scalar&
x)
299 return abs2_impl_default<Scalar,NumTraits<Scalar>::IsComplex>::run(
x);
303 template<
typename Scalar>
313 template<
typename Scalar>
330 struct sqrt_impl<
std::complex<T> >
335 return complex_sqrt<T>(
x);
339 template<
typename Scalar>
353 struct rsqrt_impl<
std::complex<T> >
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>
380 static inline RealScalar run(
const Scalar&
x)
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)
398 template<
typename Scalar>
399 struct norm1_impl : norm1_default_impl<Scalar, NumTraits<Scalar>::IsComplex> {};
401 template<
typename Scalar>
411 template<
typename Scalar>
struct hypot_impl;
413 template<
typename Scalar>
423 template<
typename OldType,
typename NewType,
typename EnableIf =
void>
427 static inline NewType run(
const OldType&
x)
429 return static_cast<NewType
>(
x);
433 template <
typename OldType>
434 struct cast_impl<OldType,
bool> {
436 static inline bool run(
const OldType&
x) {
return x != OldType(0); }
442 template<
typename OldType,
typename NewType>
443 struct cast_impl<OldType, NewType,
444 typename
std::enable_if_t<
445 !NumTraits<OldType>::IsComplex && NumTraits<NewType>::IsComplex
449 static inline NewType run(
const OldType&
x)
452 return static_cast<NewType
>(
static_cast<NewReal
>(
x));
458 template<
typename OldType,
typename NewType>
460 inline NewType
cast(
const OldType&
x)
462 return cast_impl<OldType, NewType>::run(
x);
471 #if (!EIGEN_COMP_MSVC || EIGEN_COMP_MSVC >= 1920)
473 template<
typename Scalar,
475 || is_same<Scalar, float>::value || is_same<Scalar, double>::value
476 || is_same<Scalar, long double>::value >
477 struct arg_default_impl;
479 template<
typename Scalar>
480 struct arg_default_impl<Scalar, true> {
483 static inline RealScalar run(
const Scalar&
x)
487 return static_cast<RealScalar
>(
arg(
x));
492 template<
typename Scalar>
493 struct arg_default_impl<Scalar, false> {
496 static inline RealScalar run(
const Scalar&
x)
498 return (
x < Scalar(0)) ? RealScalar(
EIGEN_PI) : RealScalar(0);
502 template<typename Scalar, bool IsComplex = NumTraits<Scalar>::IsComplex>
503 struct arg_default_impl
507 static inline RealScalar run(
const Scalar&
x)
509 return (
x < RealScalar(0)) ? RealScalar(
EIGEN_PI) : RealScalar(0);
513 template<
typename Scalar>
514 struct arg_default_impl<Scalar,true>
518 static inline RealScalar run(
const Scalar&
x)
525 template<
typename Scalar>
struct arg_impl : arg_default_impl<Scalar> {};
527 template<
typename Scalar>
538 namespace std_fallback {
542 template<
typename Scalar>
552 Scalar um1 = u - RealScalar(1);
554 return RealScalar(-1);
558 Scalar logu =
log(u);
563 template<
typename Scalar>
573 template<
typename Scalar>
586 template<
typename Scalar>
591 return static_cast<Scalar
>(
log(
x));
595 template<
typename Scalar>
596 struct log_impl<
std::complex<Scalar> > {
597 EIGEN_DEVICE_FUNC static inline std::complex<Scalar> run(
const std::complex<Scalar>& z)
607 namespace std_fallback {
610 template<
typename Scalar>
615 Scalar x1p = RealScalar(1) +
x;
616 Scalar log_1p = log_impl<Scalar>::run(x1p);
619 return (is_small || is_inf) ?
x :
x * (log_1p / (x1p - RealScalar(1)));
623 template<
typename Scalar>
635 template <
typename RealScalar>
636 struct log1p_impl<
std::complex<RealScalar> > {
640 const std::complex<RealScalar>&
x) {
645 template<
typename Scalar>
659 typedef typename ScalarBinaryOpTraits<ScalarX,ScalarY,internal::scalar_pow_op<ScalarX,ScalarY> >::ReturnType result_type;
667 template<
typename ScalarX,
typename ScalarY>
668 struct pow_impl<ScalarX,ScalarY, true>
670 typedef ScalarX result_type;
691 template<
typename Scalar,
694 struct random_default_impl {};
696 template<
typename Scalar>
697 struct random_impl : random_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
699 template<
typename Scalar>
708 template<
typename Scalar>
709 struct random_default_impl<Scalar, false, false>
711 static inline Scalar run(
const Scalar&
x,
const Scalar&
y)
713 return x + (
y-
x) * Scalar(std::rand()) / Scalar(RAND_MAX);
715 static inline Scalar run()
728 template<
unsigned int n,
int lower,
int upper>
struct meta_floor_log2_selector
730 enum { middle = (lower + upper) / 2,
738 template<
unsigned int n,
740 int upper =
sizeof(
unsigned int) * CHAR_BIT - 1,
741 int selector = meta_floor_log2_selector<n, lower, upper>::value>
742 struct meta_floor_log2 {};
744 template<
unsigned int n,
int lower,
int upper>
745 struct meta_floor_log2<n, lower, upper, meta_floor_log2_move_down>
747 enum { value = meta_floor_log2<n, lower, meta_floor_log2_selector<n, lower, upper>::middle>::value };
750 template<
unsigned int n,
int lower,
int upper>
753 enum { value = meta_floor_log2<n, meta_floor_log2_selector<n, lower, upper>::middle, upper>::value };
756 template<
unsigned int n,
int lower,
int upper>
759 enum { value = (
n >= ((
unsigned int)(1) << (lower+1))) ? lower+1 : lower };
762 template<
unsigned int n,
int lower,
int upper>
768 template<
typename Scalar>
769 struct random_default_impl<Scalar, false, true>
771 static inline Scalar run(
const Scalar&
x,
const Scalar&
y)
776 typedef typename make_unsigned<Scalar>::type ScalarU;
780 typedef std::conditional_t<(ScalarU(-1) > unsigned(-1)), ScalarU,
unsigned> ScalarX;
784 ScalarX range = ScalarX(
y) - ScalarX(
x);
787 ScalarX multiplier = 1;
788 const unsigned rand_max = RAND_MAX;
789 if (range <= rand_max) divisor = (rand_max + 1) / (range + 1);
790 else multiplier = 1 + range / (rand_max + 1);
793 offset = (unsigned(std::rand()) * multiplier) / divisor;
794 }
while (offset > range);
795 return Scalar(ScalarX(
x) + offset);
798 static inline Scalar run()
800 #ifdef EIGEN_MAKING_DOCS
803 enum { rand_bits = meta_floor_log2<(
unsigned int)(RAND_MAX)+1>::value,
804 scalar_bits =
sizeof(Scalar) * CHAR_BIT,
808 return Scalar((std::rand() >> shift) - offset);
813 template<
typename Scalar>
814 struct random_default_impl<Scalar, true, false>
816 static inline Scalar run(
const Scalar&
x,
const Scalar&
y)
818 return Scalar(random(
x.real(),
y.real()),
819 random(
x.imag(),
y.imag()));
821 static inline Scalar run()
824 return Scalar(random<RealScalar>(), random<RealScalar>());
828 template<
typename Scalar>
834 template<
typename Scalar>
842 template <
typename T>
844 std::numeric_limits<T>::has_quiet_NaN ||
845 std::numeric_limits<T>::has_signaling_NaN),
851 template <
typename T>
852 EIGEN_DEVICE_FUNC std::enable_if_t<(std::numeric_limits<T>::has_infinity || std::numeric_limits<T>::has_quiet_NaN ||
853 std::numeric_limits<T>::has_signaling_NaN) &&
861 template <
typename T>
867 template <
typename T>
875 template <
typename T>
877 std::numeric_limits<T>::has_signaling_NaN),
883 template <
typename T>
885 std::enable_if_t<(std::numeric_limits<T>::has_quiet_NaN ||
886 std::numeric_limits<T>::has_signaling_NaN) &&
895 template <
typename T>
897 template <
typename T>
899 template <
typename T>
901 template <
typename T>
907 template <
typename Scalar,
bool IsComplex = (NumTraits<Scalar>::IsComplex != 0),
908 bool IsInteger = (NumTraits<Scalar>::IsInteger != 0)>
911 static inline Scalar run(
const Scalar&
a) {
912 return Scalar((
a > Scalar(0)) - (
a < Scalar(0)));
916 template <
typename Scalar>
917 struct sign_impl<Scalar, false, false> {
919 static inline Scalar run(
const Scalar&
a) {
920 return (isnan_impl<Scalar>)(
a) ?
a
921 : Scalar((
a > Scalar(0)) - (
a < Scalar(0)));
925 template <
typename Scalar,
bool IsInteger>
926 struct sign_impl<Scalar, true, IsInteger> {
928 static inline Scalar run(
const Scalar&
a) {
931 real_type aa =
abs(
a);
932 if (aa == real_type(0))
return Scalar(0);
933 aa = real_type(1) / aa;
934 return Scalar(
a.real() * aa,
a.imag() * aa);
940 struct sign_impl<
bool, false, true> {
942 static inline bool run(
const bool&
a) {
return a; }
945 template <
typename Scalar>
951 template <typename Scalar, bool IsInteger = NumTraits<typename unpacket_traits<Scalar>::type>::IsInteger>
952 struct nearest_integer_impl {
958 template <
typename Scalar>
959 struct nearest_integer_impl<Scalar, true> {
960 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_floor(
const Scalar&
x) {
return x; }
961 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_ceil(
const Scalar&
x) {
return x; }
962 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_rint(
const Scalar&
x) {
return x; }
963 static EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar run_round(
const Scalar&
x) {
return x; }
974 #if (!defined(EIGEN_GPUCC) || defined(EIGEN_CONSTEXPR_ARE_DEVICE_FUNC))
995 return y <
x ?
y :
x;
1010 #ifndef EIGEN_GPU_COMPILE_PHASE
1015 #if defined(EIGEN_HIPCC)
1017 return (
x <
y) ?
x :
y;
1024 template<
typename T>
1028 return x <
y ?
y :
x;
1042 #ifndef EIGEN_GPU_COMPILE_PHASE
1047 #if defined(EIGEN_HIPCC)
1049 return (
x >
y) ?
x :
y;
1057 #if defined(SYCL_DEVICE_ONLY)
1060 #define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1061 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
1062 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
1063 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
1064 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
1065 #define SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1066 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_char) \
1067 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_short) \
1068 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_int) \
1069 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_long)
1070 #define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1071 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
1072 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
1073 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
1074 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
1075 #define SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1076 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uchar) \
1077 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ushort) \
1078 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_uint) \
1079 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_ulong)
1080 #define SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(NAME, FUNC) \
1081 SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY(NAME, FUNC) \
1082 SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY(NAME, FUNC)
1083 #define SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(NAME, FUNC) \
1084 SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY(NAME, FUNC) \
1085 SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY(NAME, FUNC)
1086 #define SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(NAME, FUNC) \
1087 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
1088 SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
1089 #define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(NAME, FUNC) \
1090 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, cl::sycl::cl_float) \
1091 SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC,cl::sycl::cl_double)
1092 #define SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(NAME, FUNC, RET_TYPE) \
1093 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_float) \
1094 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, cl::sycl::cl_double)
1096 #define SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
1099 EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE& x) { \
1100 return cl::sycl::FUNC(x); \
1103 #define SYCL_SPECIALIZE_UNARY_FUNC(NAME, FUNC, TYPE) \
1104 SYCL_SPECIALIZE_GEN_UNARY_FUNC(NAME, FUNC, TYPE, TYPE)
1106 #define SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE1, ARG_TYPE2) \
1109 EIGEN_ALWAYS_INLINE RET_TYPE NAME(const ARG_TYPE1& x, const ARG_TYPE2& y) { \
1110 return cl::sycl::FUNC(x, y); \
1113 #define SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE) \
1114 SYCL_SPECIALIZE_GEN1_BINARY_FUNC(NAME, FUNC, RET_TYPE, ARG_TYPE, ARG_TYPE)
1116 #define SYCL_SPECIALIZE_BINARY_FUNC(NAME, FUNC, TYPE) \
1117 SYCL_SPECIALIZE_GEN2_BINARY_FUNC(NAME, FUNC, TYPE, TYPE)
1119 SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(
mini,
min)
1120 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(
mini,
fmin)
1121 SYCL_SPECIALIZE_INTEGER_TYPES_BINARY(
maxi,
max)
1122 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(
maxi,
fmax)
1127 template<
typename Scalar>
1134 template<
typename Scalar>
1138 return internal::real_ref_impl<Scalar>::run(
x);
1141 template<
typename Scalar>
1148 template<
typename Scalar>
1155 template<
typename Scalar>
1162 template<
typename Scalar>
1166 return internal::imag_ref_impl<Scalar>::run(
x);
1169 template<
typename Scalar>
1176 template<
typename Scalar>
1183 template<
typename Scalar>
1190 template<
typename Scalar>
1200 template<
typename T>
1204 return x >
y ?
x -
y :
y -
x;
1210 return fabsf(
x -
y);
1220 #ifndef EIGEN_GPU_COMPILE_PHASE
1224 return fabsl(
x -
y);
1228 template<
typename Scalar>
1235 template<
typename Scalar>
1242 #if defined(SYCL_DEVICE_ONLY)
1243 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(hypot, hypot)
1246 template<
typename Scalar>
1253 #if defined(SYCL_DEVICE_ONLY)
1254 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
log1p,
log1p)
1257 #if defined(EIGEN_GPUCC)
1259 float log1p(
const float &
x) { return ::log1pf(
x); }
1265 template<
typename ScalarX,
typename ScalarY>
1267 inline typename internal::pow_impl<ScalarX,ScalarY>::result_type
pow(
const ScalarX&
x,
const ScalarY&
y)
1269 return internal::pow_impl<ScalarX,ScalarY>::run(
x,
y);
1272 #if defined(SYCL_DEVICE_ONLY)
1273 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(
pow,
pow)
1280 #if defined(SYCL_DEVICE_ONLY)
1281 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(
isnan,
isnan,
bool)
1282 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(
isinf,
isinf,
bool)
1283 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE(
isfinite,
isfinite,
bool)
1286 template<
typename Scalar>
1290 return internal::nearest_integer_impl<Scalar>::run_rint(
x);
1293 template<
typename Scalar>
1297 return internal::nearest_integer_impl<Scalar>::run_round(
x);
1300 #if defined(SYCL_DEVICE_ONLY)
1301 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
round,
round)
1304 template<
typename Scalar>
1308 return internal::nearest_integer_impl<Scalar>::run_floor(
x);
1311 #if defined(SYCL_DEVICE_ONLY)
1312 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
floor,
floor)
1315 #if defined(EIGEN_GPUCC)
1317 float floor(
const float &
x) { return ::floorf(
x); }
1323 template<
typename Scalar>
1327 return internal::nearest_integer_impl<Scalar>::run_ceil(
x);
1330 #if defined(SYCL_DEVICE_ONLY)
1331 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
ceil,
ceil)
1334 #if defined(EIGEN_GPUCC)
1336 float ceil(
const float &
x) { return ::ceilf(
x); }
1349 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 };
1355 return table[(
v * 0x07C4ACDDU) >> 27];
1367 template<
typename Scalar>
1379 #if defined(SYCL_DEVICE_ONLY)
1380 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
sqrt,
sqrt)
1384 template<
typename T>
1388 return internal::rsqrt_impl<T>::run(
x);
1391 template<
typename T>
1394 return internal::log_impl<T>::run(
x);
1397 #if defined(SYCL_DEVICE_ONLY)
1398 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
log,
log)
1402 #if defined(EIGEN_GPUCC)
1404 float log(
const float &
x) { return ::logf(
x); }
1410 template<
typename T>
1418 template<
typename T>
1425 #if defined(SYCL_DEVICE_ONLY)
1426 SYCL_SPECIALIZE_INTEGER_TYPES_UNARY(
abs,
abs)
1427 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
abs, fabs)
1430 #if defined(EIGEN_GPUCC)
1432 float abs(
const float &
x) { return ::fabsf(
x); }
1435 double abs(
const double &
x) { return ::fabs(
x); }
1438 float abs(
const std::complex<float>&
x) {
1439 return ::hypotf(
x.real(),
x.imag());
1443 double abs(
const std::complex<double>&
x) {
1444 return ::hypot(
x.real(),
x.imag());
1450 template <
typename Scalar>
1452 static constexpr
size_t Size =
sizeof(Scalar);
1453 static constexpr
size_t Shift = (CHAR_BIT * Size) - 1;
1458 Scalar result = bit_cast<Scalar, intSize_t>(
a);
1462 template <
typename Scalar>
1464 static constexpr
size_t Size =
sizeof(Scalar);
1465 static constexpr
size_t Shift = (CHAR_BIT * Size) - 1;
1468 template <
typename Scalar>
1474 template <
typename Scalar>
1479 template<
typename T>
1486 #if defined(SYCL_DEVICE_ONLY)
1487 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
exp,
exp)
1490 #if defined(EIGEN_GPUCC)
1492 float exp(
const float &
x) { return ::expf(
x); }
1498 std::complex<float>
exp(
const std::complex<float>&
x) {
1499 float com = ::expf(
x.real());
1500 float res_real = com * ::cosf(
x.imag());
1501 float res_imag = com * ::sinf(
x.imag());
1502 return std::complex<float>(res_real, res_imag);
1506 std::complex<double>
exp(
const std::complex<double>&
x) {
1507 double com =
::exp(
x.real());
1508 double res_real = com *
::cos(
x.imag());
1509 double res_imag = com *
::sin(
x.imag());
1510 return std::complex<double>(res_real, res_imag);
1514 template<
typename Scalar>
1521 #if defined(SYCL_DEVICE_ONLY)
1522 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
expm1,
expm1)
1525 #if defined(EIGEN_GPUCC)
1527 float expm1(
const float &
x) { return ::expm1f(
x); }
1533 template<
typename T>
1540 #if defined(SYCL_DEVICE_ONLY)
1541 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
cos,
cos)
1544 #if defined(EIGEN_GPUCC)
1546 float cos(
const float &
x) { return ::cosf(
x); }
1552 template<
typename T>
1559 #if defined(SYCL_DEVICE_ONLY)
1560 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
sin,
sin)
1563 #if defined(EIGEN_GPUCC)
1565 float sin(
const float &
x) { return ::sinf(
x); }
1571 template<
typename T>
1578 #if defined(SYCL_DEVICE_ONLY)
1579 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
tan,
tan)
1582 #if defined(EIGEN_GPUCC)
1584 float tan(
const float &
x) { return ::tanf(
x); }
1590 template<
typename T>
1597 template<
typename T>
1601 return static_cast<T>(
acosh(
x));
1604 #if defined(SYCL_DEVICE_ONLY)
1605 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
acos,
acos)
1606 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
acosh,
acosh)
1609 #if defined(EIGEN_GPUCC)
1611 float acos(
const float &
x) { return ::acosf(
x); }
1617 template<
typename T>
1624 template<
typename T>
1628 return static_cast<T>(
asinh(
x));
1631 #if defined(SYCL_DEVICE_ONLY)
1632 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
asin,
asin)
1633 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
asinh,
asinh)
1636 #if defined(EIGEN_GPUCC)
1638 float asin(
const float &
x) { return ::asinf(
x); }
1644 template<
typename T>
1648 return static_cast<T>(
atan(
x));
1651 template <typename T, std::enable_if_t<!NumTraits<T>::IsComplex,
int> = 0>
1654 return static_cast<T>(
atan2(
y,
x));
1657 template<
typename T>
1661 return static_cast<T>(
atanh(
x));
1664 #if defined(SYCL_DEVICE_ONLY)
1665 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
atan,
atan)
1666 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
atanh,
atanh)
1669 #if defined(EIGEN_GPUCC)
1671 float atan(
const float &
x) { return ::atanf(
x); }
1678 template<
typename T>
1682 return static_cast<T>(
cosh(
x));
1685 #if defined(SYCL_DEVICE_ONLY)
1686 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
cosh,
cosh)
1689 #if defined(EIGEN_GPUCC)
1691 float cosh(
const float &
x) { return ::coshf(
x); }
1697 template<
typename T>
1701 return static_cast<T>(
sinh(
x));
1704 #if defined(SYCL_DEVICE_ONLY)
1705 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
sinh,
sinh)
1708 #if defined(EIGEN_GPUCC)
1710 float sinh(
const float &
x) { return ::sinhf(
x); }
1716 template<
typename T>
1723 #if (!defined(EIGEN_GPUCC)) && EIGEN_FAST_MATH && !defined(SYCL_DEVICE_ONLY)
1728 #if defined(SYCL_DEVICE_ONLY)
1729 SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(
tanh,
tanh)
1732 #if defined(EIGEN_GPUCC)
1734 float tanh(
const float &
x) { return ::tanhf(
x); }
1740 template <
typename T>
1747 #if defined(SYCL_DEVICE_ONLY)
1748 SYCL_SPECIALIZE_FLOATING_TYPES_BINARY(
fmod,
fmod)
1751 #if defined(EIGEN_GPUCC)
1754 float fmod(
const float&
a,
const float&
b) {
1755 return ::fmodf(
a,
b);
1760 double fmod(
const double&
a,
const double&
b) {
1765 #if defined(SYCL_DEVICE_ONLY)
1766 #undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_BINARY
1767 #undef SYCL_SPECIALIZE_SIGNED_INTEGER_TYPES_UNARY
1768 #undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_BINARY
1769 #undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
1770 #undef SYCL_SPECIALIZE_INTEGER_TYPES_BINARY
1771 #undef SYCL_SPECIALIZE_UNSIGNED_INTEGER_TYPES_UNARY
1772 #undef SYCL_SPECIALIZE_FLOATING_TYPES_BINARY
1773 #undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY
1774 #undef SYCL_SPECIALIZE_FLOATING_TYPES_UNARY_FUNC_RET_TYPE
1775 #undef SYCL_SPECIALIZE_GEN_UNARY_FUNC
1776 #undef SYCL_SPECIALIZE_UNARY_FUNC
1777 #undef SYCL_SPECIALIZE_GEN1_BINARY_FUNC
1778 #undef SYCL_SPECIALIZE_GEN2_BINARY_FUNC
1779 #undef SYCL_SPECIALIZE_BINARY_FUNC
1786 template<
typename T>
1792 template<
typename T>
1798 template<
typename T>
1808 template<
typename Scalar,
1811 struct scalar_fuzzy_default_impl {};
1813 template<
typename Scalar>
1814 struct scalar_fuzzy_default_impl<Scalar, false, false>
1818 static inline bool isMuchSmallerThan(
const Scalar&
x,
const OtherScalar&
y,
const RealScalar& prec)
1823 static inline bool isApprox(
const Scalar&
x,
const Scalar&
y,
const RealScalar& prec)
1828 static inline bool isApproxOrLessThan(
const Scalar&
x,
const Scalar&
y,
const RealScalar& prec)
1834 template<
typename Scalar>
1835 struct scalar_fuzzy_default_impl<Scalar, false, true>
1839 static inline bool isMuchSmallerThan(
const Scalar&
x,
const Scalar&,
const RealScalar&)
1841 return x == Scalar(0);
1844 static inline bool isApprox(
const Scalar&
x,
const Scalar&
y,
const RealScalar&)
1855 template<
typename Scalar>
1856 struct scalar_fuzzy_default_impl<Scalar, true, false>
1860 static inline bool isMuchSmallerThan(
const Scalar&
x,
const OtherScalar&
y,
const RealScalar& prec)
1865 static inline bool isApprox(
const Scalar&
x,
const Scalar&
y,
const RealScalar& prec)
1871 template<
typename Scalar>
1872 struct scalar_fuzzy_impl : scalar_fuzzy_default_impl<Scalar, NumTraits<Scalar>::IsComplex, NumTraits<Scalar>::IsInteger> {};
1878 return scalar_fuzzy_impl<Scalar>::template isMuchSmallerThan<OtherScalar>(
x,
y, precision);
1899 template<>
struct random_impl<
bool>
1901 static inline bool run()
1903 return random<int>(0,1)==0 ? false :
true;
1906 static inline bool run(
const bool&
a,
const bool&
b)
1908 return random<int>(
a,
b)==0 ? false :
true;
1912 template<>
struct scalar_fuzzy_impl<
bool>
1914 typedef bool RealScalar;
1923 static inline bool isApprox(
bool x,
bool y,
bool)
1942 template <
typename RealScalar>
1943 struct expm1_impl<
std::complex<RealScalar> > {
1947 const std::complex<RealScalar>&
x) {
1948 RealScalar xr =
x.real();
1949 RealScalar xi =
x.imag();
1959 RealScalar erm1 = numext::expm1<RealScalar>(xr);
1960 RealScalar er = erm1 + RealScalar(1.);
1961 RealScalar sin2 =
numext::sin(xi / RealScalar(2.));
1964 RealScalar real_part = erm1 - RealScalar(2.) * er * sin2;
1965 return std::complex<RealScalar>(real_part, er * s);
1969 template<
typename T>
1977 #if defined(EIGEN_GPU_COMPILE_PHASE)
1978 template<
typename T>
1979 struct conj_impl<
std::complex<T>, true>
1982 static inline std::complex<T> run(
const std::complex<T>&
x)
const AtanReturnType atan() const
const AcosReturnType acos() const
const AsinReturnType asin() const
const ExpReturnType exp() const
const ArgReturnType arg() const
const CeilReturnType ceil() const
const SinReturnType sin() const
const SinhReturnType sinh() const
const TanReturnType tan() const
const Log1pReturnType log1p() const
const Expm1ReturnType expm1() const
const FloorReturnType floor() const
const CoshReturnType cosh() const
const TanhReturnType tanh() const
const LogReturnType log() const
const CosReturnType cos() const
Array< int, Dynamic, 1 > v
const ImagReturnType imag() const
RealReturnType real() const
#define EIGEN_ALWAYS_INLINE
#define EIGEN_USING_STD(FUNC)
#define EIGEN_DEVICE_FUNC
#define EIGEN_NOT_A_MACRO
#define EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS
#define EIGEN_MATHFUNC_IMPL(func, scalar)
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define EIGEN_STATIC_ASSERT_NON_INTEGER(TYPE)
Eigen::Triplet< double > T
bfloat16 fmax(const bfloat16 &a, const bfloat16 &b)
bfloat16() max(const bfloat16 &a, const bfloat16 &b)
bfloat16 fmin(const bfloat16 &a, const bfloat16 &b)
bfloat16() min(const bfloat16 &a, const bfloat16 &b)
@ meta_floor_log2_terminate
@ meta_floor_log2_move_up
@ meta_floor_log2_move_down
constexpr int plain_enum_min(A a, B b)
std::enable_if_t<!(std::numeric_limits< T >::has_quiet_NaN||std::numeric_limits< T >::has_signaling_NaN), bool > isnan_impl(const T &)
constexpr int plain_enum_max(A a, B b)
bool isApproxOrLessThan(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
std::enable_if_t<!(std::numeric_limits< T >::has_infinity||std::numeric_limits< T >::has_quiet_NaN||std::numeric_limits< T >::has_signaling_NaN), bool > isfinite_impl(const T &)
std::enable_if_t<!std::numeric_limits< T >::has_infinity, bool > isinf_impl(const T &)
std::complex< T > complex_log(const std::complex< T > &z)
std::complex< T > complex_rsqrt(const std::complex< T > &a_x)
NewType cast(const OldType &x)
std::complex< T > complex_sqrt(const std::complex< T > &a_x)
bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
T generic_fast_tanh_float(const T &a_x)
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
typename add_const_on_value_type< T >::type add_const_on_value_type_t
EIGEN_MATHFUNC_RETVAL(random, Scalar) random(const Scalar &x
Scalar round(const Scalar &x)
bool equal_strict(const X &x, const Y &y)
EIGEN_ALWAYS_INLINE T cosh(const T &x)
EIGEN_ALWAYS_INLINE T tan(const T &x)
EIGEN_MATHFUNC_RETVAL(real, Scalar) real(const Scalar &x)
EIGEN_ALWAYS_INLINE T absdiff(const T &x, const T &y)
EIGEN_ALWAYS_INLINE bool() isinf(const Eigen::bfloat16 &h)
EIGEN_ALWAYS_INLINE T acosh(const T &x)
internal::add_const_on_value_type_t< EIGEN_MATHFUNC_RETVAL(imag_ref, Scalar) > imag_ref(const Scalar &x)
EIGEN_ALWAYS_INLINE T atan(const T &x)
EIGEN_ALWAYS_INLINE T atanh(const T &x)
internal::add_const_on_value_type_t< EIGEN_MATHFUNC_RETVAL(real_ref, Scalar) > real_ref(const Scalar &x)
EIGEN_ALWAYS_INLINE T sin(const T &x)
internal::pow_impl< ScalarX, ScalarY >::result_type pow(const ScalarX &x, const ScalarY &y)
Scalar rint(const Scalar &x)
EIGEN_ALWAYS_INLINE T tanh(const T &x)
EIGEN_ALWAYS_INLINE T maxi(const T &x, const T &y)
EIGEN_ALWAYS_INLINE T acos(const T &x)
EIGEN_ALWAYS_INLINE float sqrt(const float &x)
EIGEN_ALWAYS_INLINE T exp(const T &x)
EIGEN_ALWAYS_INLINE T sinh(const T &x)
Scalar() floor(const Scalar &x)
EIGEN_ALWAYS_INLINE T atan2(const T &y, const T &x)
Scalar() ceil(const Scalar &x)
EIGEN_ALWAYS_INLINE T fmod(const T &a, const T &b)
EIGEN_ALWAYS_INLINE T asinh(const T &x)
static constexpr EIGEN_ALWAYS_INLINE Scalar signbit(const Scalar &x)
EIGEN_ALWAYS_INLINE bool() isnan(const Eigen::bfloat16 &h)
EIGEN_ALWAYS_INLINE bool() isfinite(const Eigen::bfloat16 &h)
EIGEN_ALWAYS_INLINE T asin(const T &x)
EIGEN_ALWAYS_INLINE T mini(const T &x, const T &y)
EIGEN_ALWAYS_INLINE T cos(const T &x)
EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)
EIGEN_ALWAYS_INLINE T rsqrt(const T &x)
EIGEN_ALWAYS_INLINE T log(const T &x)
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS bool sqrt< bool >(const bool &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_sign_op< typename Derived::Scalar >, const Derived > sign(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_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_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_sqrt_op< typename Derived::Scalar >, const Derived > sqrt(const Eigen::ArrayBase< Derived > &x)
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
static EIGEN_ALWAYS_INLINE Scalar run(const Scalar &x)
typename get_integer_by_size< Size >::signed_type intSize_t
static constexpr EIGEN_ALWAYS_INLINE Scalar run(const Scalar &)
static constexpr EIGEN_ALWAYS_INLINE Scalar run(const Scalar &x)