From 68d1897e8a07f1ebef24221dbcc4a42fdabae1a0 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Fri, 26 Aug 2016 15:30:55 +0200 Subject: Make sure that our log1p implementation is called as a last resort only. --- Eigen/src/Core/MathFunctions.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'Eigen/src/Core') diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 256dc8e94..a18b79408 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -459,30 +459,33 @@ struct arg_retval /**************************************************************************** * Implementation of log1p * ****************************************************************************/ -template::IsComplex > -struct log1p_impl -{ - static EIGEN_DEVICE_FUNC inline Scalar run(const Scalar& x) - { + +namespace std_fallback { + // fallback log1p implementation in case there is no log1p(Scalar) function in namespace of Scalar, + // or that there is no suitable std::log1p function available + template + EIGEN_DEVICE_FUNC inline Scalar log1p(const Scalar& x) { EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) typedef typename NumTraits::Real RealScalar; EIGEN_USING_STD_MATH(log); Scalar x1p = RealScalar(1) + x; return ( x1p == Scalar(1) ) ? x : x * ( log(x1p) / (x1p - RealScalar(1)) ); } -}; +} -#if EIGEN_HAS_CXX11_MATH && !defined(__CUDACC__) template -struct log1p_impl { +struct log1p_impl { static inline Scalar run(const Scalar& x) { EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar) + #if EIGEN_HAS_CXX11_MATH using std::log1p; + #endif + using std_fallback::log1p; return log1p(x); } }; -#endif + template struct log1p_retval -- cgit v1.2.3