Simplified the implementation of lgamma, erf, and erfc

This commit is contained in:
Benoit Steiner 2015-12-08 14:17:34 -08:00
parent e535450573
commit 53b196aa5f

View File

@ -11,42 +11,6 @@
#define EIGEN_SPECIAL_FUNCTIONS_H
namespace Eigen {
namespace internal {
template <typename Scalar>
EIGEN_STRONG_INLINE Scalar __lgamma(Scalar x) {
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
THIS_TYPE_IS_NOT_SUPPORTED);
}
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __lgamma<float>(float x) { return lgammaf(x); }
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __lgamma<double>(double x) { return lgamma(x); }
template <typename Scalar>
EIGEN_STRONG_INLINE Scalar __erf(Scalar x) {
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
THIS_TYPE_IS_NOT_SUPPORTED);
}
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __erf<float>(float x) { return erff(x); }
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __erf<double>(double x) { return erf(x); }
template <typename Scalar>
EIGEN_STRONG_INLINE Scalar __erfc(Scalar x) {
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
THIS_TYPE_IS_NOT_SUPPORTED);
}
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE float __erfc<float>(float x) { return erfcf(x); }
template <> EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE double __erfc<double>(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<Scalar>(x);
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
THIS_TYPE_IS_NOT_SUPPORTED);
}
};
template<>
struct lgamma_impl<float>
{
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE double run(const float& x) { return ::lgammaf(x); }
};
template<>
struct lgamma_impl<double>
{
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE double run(const double& x) { return ::lgamma(x); }
};
template<typename Scalar>
struct lgamma_retval
{
@ -79,10 +58,25 @@ struct erf_impl
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Scalar run(const Scalar& x)
{
return __erf<Scalar>(x);
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
THIS_TYPE_IS_NOT_SUPPORTED);
}
};
template<>
struct erf_impl<float>
{
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE float run(const float& x) { return ::erff(x); }
};
template<>
struct erf_impl<double>
{
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE double run(const double& x) { return ::erf(x); }
};
template<typename Scalar>
struct erf_retval
{
@ -99,10 +93,25 @@ struct erfc_impl
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE Scalar run(const Scalar& x)
{
return __erfc<Scalar>(x);
EIGEN_STATIC_ASSERT((internal::is_same<Scalar, Scalar>::value == false),
THIS_TYPE_IS_NOT_SUPPORTED);
}
};
template<>
struct erfc_impl<float>
{
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE float run(const float x) { return ::erfcf(x); }
};
template<>
struct erfc_impl<double>
{
EIGEN_DEVICE_FUNC
static EIGEN_STRONG_INLINE double run(const double x) { return ::erfc(x); }
};
template<typename Scalar>
struct erfc_retval
{