From 1395056fc0c077b0a1e9b1854c6f18d6bbb9ee61 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 20 May 2016 14:58:19 +0200 Subject: [PATCH] Make EIGEN_HAS_C99_MATH user configurable --- Eigen/src/Core/SpecialFunctions.h | 12 ++++++------ Eigen/src/Core/arch/CUDA/Half.h | 2 +- Eigen/src/Core/util/Macros.h | 6 +++++- test/array.cpp | 6 +++--- test/packetmath.cpp | 4 ++-- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Eigen/src/Core/SpecialFunctions.h b/Eigen/src/Core/SpecialFunctions.h index 4cf58c510..f34c7bcda 100644 --- a/Eigen/src/Core/SpecialFunctions.h +++ b/Eigen/src/Core/SpecialFunctions.h @@ -116,7 +116,7 @@ struct lgamma_retval { typedef Scalar type; }; -#ifdef EIGEN_HAS_C99_MATH +#if EIGEN_HAS_C99_MATH template <> struct lgamma_impl { EIGEN_DEVICE_FUNC @@ -336,7 +336,7 @@ struct erf_retval { typedef Scalar type; }; -#ifdef EIGEN_HAS_C99_MATH +#if EIGEN_HAS_C99_MATH template <> struct erf_impl { EIGEN_DEVICE_FUNC @@ -369,7 +369,7 @@ struct erfc_retval { typedef Scalar type; }; -#ifdef EIGEN_HAS_C99_MATH +#if EIGEN_HAS_C99_MATH template <> struct erfc_impl { EIGEN_DEVICE_FUNC @@ -426,7 +426,7 @@ struct igamma_helper { } }; -#ifndef EIGEN_HAS_C99_MATH +#if !EIGEN_HAS_C99_MATH template struct igammac_impl { @@ -608,7 +608,7 @@ struct igamma_retval { typedef Scalar type; }; -#ifndef EIGEN_HAS_C99_MATH +#if !EIGEN_HAS_C99_MATH template struct igamma_impl { @@ -967,7 +967,7 @@ struct polygamma_retval { typedef Scalar type; }; -#ifndef EIGEN_HAS_C99_MATH +#if !EIGEN_HAS_C99_MATH template struct polygamma_impl { diff --git a/Eigen/src/Core/arch/CUDA/Half.h b/Eigen/src/Core/arch/CUDA/Half.h index 3ead82829..d081c7392 100644 --- a/Eigen/src/Core/arch/CUDA/Half.h +++ b/Eigen/src/Core/arch/CUDA/Half.h @@ -466,7 +466,7 @@ template <> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half maxi(const Eigen:: #endif } -#ifdef EIGEN_HAS_C99_MATH +#if EIGEN_HAS_C99_MATH template<> EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half lgamma(const Eigen::half& a) { return Eigen::half(Eigen::numext::lgamma(static_cast(a))); } diff --git a/Eigen/src/Core/util/Macros.h b/Eigen/src/Core/util/Macros.h index 7fb194a40..3fcef82b6 100644 --- a/Eigen/src/Core/util/Macros.h +++ b/Eigen/src/Core/util/Macros.h @@ -360,11 +360,15 @@ #endif // Does the compiler support C99? +#ifndef EIGEN_HAS_C99_MATH #if EIGEN_MAX_CPP_VER>=11 && \ ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)) \ || (defined(__GNUC__) && defined(_GLIBCXX_USE_C99)) \ || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER))) -#define EIGEN_HAS_C99_MATH 1 + #define EIGEN_HAS_C99_MATH 1 +#else + #define EIGEN_HAS_C99_MATH 0 +#endif #endif // Does the compiler support result_of? diff --git a/test/array.cpp b/test/array.cpp index ed81b0069..a028c7528 100644 --- a/test/array.cpp +++ b/test/array.cpp @@ -217,7 +217,7 @@ template void array_real(const ArrayType& m) VERIFY_IS_APPROX(m1.sinh(), sinh(m1)); VERIFY_IS_APPROX(m1.cosh(), cosh(m1)); VERIFY_IS_APPROX(m1.tanh(), tanh(m1)); -#ifdef EIGEN_HAS_C99_MATH +#if EIGEN_HAS_C99_MATH VERIFY_IS_APPROX(m1.lgamma(), lgamma(m1)); VERIFY_IS_APPROX(m1.digamma(), digamma(m1)); VERIFY_IS_APPROX(m1.erf(), erf(m1)); @@ -312,7 +312,7 @@ template void array_real(const ArrayType& m) -#ifdef EIGEN_HAS_C99_MATH +#if EIGEN_HAS_C99_MATH // check special functions (comparing against numpy implementation) if (!NumTraits::IsComplex) { @@ -582,7 +582,7 @@ template void array_special_functions() } -#ifdef EIGEN_HAS_C99_MATH +#if EIGEN_HAS_C99_MATH { ArrayType n(11), x(11), res(11), ref(11); n << 1, 1, 1, 1.5, 17, 31, 28, 8, 42, 147, 170; diff --git a/test/packetmath.cpp b/test/packetmath.cpp index 0d96d614e..3e4eb1414 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -367,7 +367,7 @@ template void packetmath_real() VERIFY((numext::isnan)(data2[0])); } -#ifdef EIGEN_HAS_C99_MATH +#if EIGEN_HAS_C99_MATH { data1[0] = std::numeric_limits::quiet_NaN(); packet_helper::HasLGamma,Packet> h; @@ -398,7 +398,7 @@ template void packetmath_real() data1[internal::random(0, PacketSize)] = 0; CHECK_CWISE1_IF(PacketTraits::HasSqrt, std::sqrt, internal::psqrt); CHECK_CWISE1_IF(PacketTraits::HasLog, std::log, internal::plog); -#if defined(EIGEN_HAS_C99_MATH) && (__cplusplus > 199711L) +#if EIGEN_HAS_C99_MATH && (__cplusplus > 199711L) CHECK_CWISE1_IF(internal::packet_traits::HasLGamma, std::lgamma, internal::plgamma); CHECK_CWISE1_IF(internal::packet_traits::HasErf, std::erf, internal::perf); CHECK_CWISE1_IF(internal::packet_traits::HasErfc, std::erfc, internal::perfc);