mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-30 15:54:13 +08:00
Make sure that our log1p implementation is called as a last resort only.
This commit is contained in:
parent
fe60856fed
commit
68d1897e8a
@ -459,30 +459,33 @@ struct arg_retval
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Implementation of log1p *
|
* Implementation of log1p *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
template<typename Scalar, bool isComplex = NumTraits<Scalar>::IsComplex >
|
|
||||||
struct log1p_impl
|
namespace std_fallback {
|
||||||
{
|
// fallback log1p implementation in case there is no log1p(Scalar) function in namespace of Scalar,
|
||||||
static EIGEN_DEVICE_FUNC inline Scalar run(const Scalar& x)
|
// or that there is no suitable std::log1p function available
|
||||||
{
|
template<typename Scalar>
|
||||||
|
EIGEN_DEVICE_FUNC inline Scalar log1p(const Scalar& x) {
|
||||||
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
||||||
typedef typename NumTraits<Scalar>::Real RealScalar;
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||||
EIGEN_USING_STD_MATH(log);
|
EIGEN_USING_STD_MATH(log);
|
||||||
Scalar x1p = RealScalar(1) + x;
|
Scalar x1p = RealScalar(1) + x;
|
||||||
return ( x1p == Scalar(1) ) ? x : x * ( log(x1p) / (x1p - RealScalar(1)) );
|
return ( x1p == Scalar(1) ) ? x : x * ( log(x1p) / (x1p - RealScalar(1)) );
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
#if EIGEN_HAS_CXX11_MATH && !defined(__CUDACC__)
|
|
||||||
template<typename Scalar>
|
template<typename Scalar>
|
||||||
struct log1p_impl<Scalar, false> {
|
struct log1p_impl {
|
||||||
static inline Scalar run(const Scalar& x)
|
static inline Scalar run(const Scalar& x)
|
||||||
{
|
{
|
||||||
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
||||||
|
#if EIGEN_HAS_CXX11_MATH
|
||||||
using std::log1p;
|
using std::log1p;
|
||||||
|
#endif
|
||||||
|
using std_fallback::log1p;
|
||||||
return log1p(x);
|
return log1p(x);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#endif
|
|
||||||
|
|
||||||
template<typename Scalar>
|
template<typename Scalar>
|
||||||
struct log1p_retval
|
struct log1p_retval
|
||||||
|
Loading…
x
Reference in New Issue
Block a user