Use lgamma_r if it is available (update check for glibc 2.19+)

This commit is contained in:
Eugene Zhulenev 2020-10-08 00:26:45 +00:00 committed by Rasmus Munk Larsen
parent b431024404
commit 2279f2c62f

View File

@ -57,11 +57,23 @@ struct lgamma_retval {
};
#if EIGEN_HAS_C99_MATH
// Since glibc 2.19
#if defined(__GLIBC__) && ((__GLIBC__>=2 && __GLIBC_MINOR__ >= 19) || __GLIBC__>2) \
&& (defined(_DEFAULT_SOURCE) || defined(_BSD_SOURCE) || defined(_SVID_SOURCE))
#define HAS_LGAMMA_R
#endif
// Glibc versions before 2.19
#if defined(__GLIBC__) && ((__GLIBC__==2 && __GLIBC_MINOR__ < 19) || __GLIBC__<2) \
&& (defined(_BSD_SOURCE) || defined(_SVID_SOURCE))
#define HAS_LGAMMA_R
#endif
template <>
struct lgamma_impl<float> {
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE float run(float x) {
#if !defined(EIGEN_GPU_COMPILE_PHASE) && (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) && !defined(__APPLE__)
#if !defined(EIGEN_GPU_COMPILE_PHASE) && defined (HAS_LGAMMA_R) && !defined(__APPLE__)
int dummy;
return ::lgammaf_r(x, &dummy);
#elif defined(SYCL_DEVICE_ONLY)
@ -76,7 +88,7 @@ template <>
struct lgamma_impl<double> {
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE double run(double x) {
#if !defined(EIGEN_GPU_COMPILE_PHASE) && (defined(_BSD_SOURCE) || defined(_SVID_SOURCE)) && !defined(__APPLE__)
#if !defined(EIGEN_GPU_COMPILE_PHASE) && defined(HAS_LGAMMA_R) && !defined(__APPLE__)
int dummy;
return ::lgamma_r(x, &dummy);
#elif defined(SYCL_DEVICE_ONLY)
@ -86,6 +98,8 @@ struct lgamma_impl<double> {
#endif
}
};
#undef HAS_LGAMMA_R
#endif
/****************************************************************************