From 53b196aa5fb503ab3707887eea226eec56943380 Mon Sep 17 00:00:00 2001 From: Benoit Steiner Date: Tue, 8 Dec 2015 14:17:34 -0800 Subject: [PATCH] Simplified the implementation of lgamma, erf, and erfc --- Eigen/src/Core/SpecialFunctions.h | 87 +++++++++++++++++-------------- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/Eigen/src/Core/SpecialFunctions.h b/Eigen/src/Core/SpecialFunctions.h index ae8f0105a..f90f1b81b 100644 --- a/Eigen/src/Core/SpecialFunctions.h +++ b/Eigen/src/Core/SpecialFunctions.h @@ -11,42 +11,6 @@ #define EIGEN_SPECIAL_FUNCTIONS_H namespace Eigen { - -namespace internal { - -template -EIGEN_STRONG_INLINE Scalar __lgamma(Scalar x) { - EIGEN_STATIC_ASSERT((internal::is_same::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); -} - -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __lgamma(float x) { return lgammaf(x); } -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __lgamma(double x) { return lgamma(x); } - -template -EIGEN_STRONG_INLINE Scalar __erf(Scalar x) { - EIGEN_STATIC_ASSERT((internal::is_same::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); -} - -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __erf(float x) { return erff(x); } -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __erf(double x) { return erf(x); } - -template -EIGEN_STRONG_INLINE Scalar __erfc(Scalar x) { - EIGEN_STATIC_ASSERT((internal::is_same::value == false), - THIS_TYPE_IS_NOT_SUPPORTED); -} - -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __erfc(float x) { return erfcf(x); } -template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __erfc(double x) { return erfc(x); } - -} // end namespace internal - -/**************************************************************************** - * Implementations * - ****************************************************************************/ - namespace internal { /**************************************************************************** @@ -59,10 +23,25 @@ struct lgamma_impl EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Scalar& x) { - return __lgamma(x); + EIGEN_STATIC_ASSERT((internal::is_same::value == false), + THIS_TYPE_IS_NOT_SUPPORTED); } }; +template<> +struct lgamma_impl +{ + EIGEN_DEVICE_FUNC + static EIGEN_STRONG_INLINE double run(const float& x) { return ::lgammaf(x); } +}; + +template<> +struct lgamma_impl +{ + EIGEN_DEVICE_FUNC + static EIGEN_STRONG_INLINE double run(const double& x) { return ::lgamma(x); } +}; + template struct lgamma_retval { @@ -79,10 +58,25 @@ struct erf_impl EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Scalar& x) { - return __erf(x); + EIGEN_STATIC_ASSERT((internal::is_same::value == false), + THIS_TYPE_IS_NOT_SUPPORTED); } }; +template<> +struct erf_impl +{ + EIGEN_DEVICE_FUNC + static EIGEN_STRONG_INLINE float run(const float& x) { return ::erff(x); } +}; + +template<> +struct erf_impl +{ + EIGEN_DEVICE_FUNC + static EIGEN_STRONG_INLINE double run(const double& x) { return ::erf(x); } +}; + template struct erf_retval { @@ -99,10 +93,25 @@ struct erfc_impl EIGEN_DEVICE_FUNC static EIGEN_STRONG_INLINE Scalar run(const Scalar& x) { - return __erfc(x); + EIGEN_STATIC_ASSERT((internal::is_same::value == false), + THIS_TYPE_IS_NOT_SUPPORTED); } }; +template<> +struct erfc_impl +{ + EIGEN_DEVICE_FUNC + static EIGEN_STRONG_INLINE float run(const float x) { return ::erfcf(x); } +}; + +template<> +struct erfc_impl +{ + EIGEN_DEVICE_FUNC + static EIGEN_STRONG_INLINE double run(const double x) { return ::erfc(x); } +}; + template struct erfc_retval {