mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
Unconditionally enable CXX11 math.
This commit is contained in:
parent
e5794873cb
commit
80efbfdeda
@ -68,11 +68,9 @@ namespace Eigen
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(sinh,scalar_sinh_op,hyperbolic sine,\sa ArrayBase::sinh)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(cosh,scalar_cosh_op,hyperbolic cosine,\sa ArrayBase::cosh)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(tanh,scalar_tanh_op,hyperbolic tangent,\sa ArrayBase::tanh)
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(asinh,scalar_asinh_op,inverse hyperbolic sine,\sa ArrayBase::asinh)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(acosh,scalar_acosh_op,inverse hyperbolic cosine,\sa ArrayBase::acosh)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(atanh,scalar_atanh_op,inverse hyperbolic tangent,\sa ArrayBase::atanh)
|
||||
#endif
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(logistic,scalar_logistic_op,logistic function,\sa ArrayBase::logistic)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(lgamma,scalar_lgamma_op,natural logarithm of the gamma function,\sa ArrayBase::lgamma)
|
||||
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(digamma,scalar_digamma_op,derivative of lgamma,\sa ArrayBase::digamma)
|
||||
|
@ -524,54 +524,11 @@ struct round_impl
|
||||
EIGEN_DEVICE_FUNC
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
EIGEN_USING_STD(round);
|
||||
#endif
|
||||
return Scalar(round(x));
|
||||
}
|
||||
};
|
||||
|
||||
#if !EIGEN_HAS_CXX11_MATH
|
||||
#if EIGEN_HAS_C99_MATH
|
||||
// Use ::roundf for float.
|
||||
template<>
|
||||
struct round_impl<float> {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static inline float run(const float& x)
|
||||
{
|
||||
return ::roundf(x);
|
||||
}
|
||||
};
|
||||
#else
|
||||
template<typename Scalar>
|
||||
struct round_using_floor_ceil_impl
|
||||
{
|
||||
EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
|
||||
|
||||
EIGEN_DEVICE_FUNC
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
// Without C99 round/roundf, resort to floor/ceil.
|
||||
EIGEN_USING_STD(floor);
|
||||
EIGEN_USING_STD(ceil);
|
||||
// If not enough precision to resolve a decimal at all, return the input.
|
||||
// Otherwise, adding 0.5 can trigger an increment by 1.
|
||||
const Scalar limit = Scalar(1ull << (NumTraits<Scalar>::digits() - 1));
|
||||
if (x >= limit || x <= -limit) {
|
||||
return x;
|
||||
}
|
||||
return (x > Scalar(0)) ? Scalar(floor(x + Scalar(0.5))) : Scalar(ceil(x - Scalar(0.5)));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct round_impl<float> : round_using_floor_ceil_impl<float> {};
|
||||
|
||||
template<>
|
||||
struct round_impl<double> : round_using_floor_ceil_impl<double> {};
|
||||
#endif // EIGEN_HAS_C99_MATH
|
||||
#endif // !EIGEN_HAS_CXX11_MATH
|
||||
|
||||
template<typename Scalar>
|
||||
struct round_retval
|
||||
{
|
||||
@ -589,32 +546,11 @@ struct rint_impl {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
EIGEN_USING_STD(rint);
|
||||
#endif
|
||||
return rint(x);
|
||||
}
|
||||
};
|
||||
|
||||
#if !EIGEN_HAS_CXX11_MATH
|
||||
template<>
|
||||
struct rint_impl<double> {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static inline double run(const double& x)
|
||||
{
|
||||
return ::rint(x);
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct rint_impl<float> {
|
||||
EIGEN_DEVICE_FUNC
|
||||
static inline float run(const float& x)
|
||||
{
|
||||
return ::rintf(x);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
template<typename Scalar>
|
||||
struct rint_retval
|
||||
{
|
||||
@ -627,7 +563,7 @@ struct rint_retval
|
||||
|
||||
// Visual Studio 2017 has a bug where arg(float) returns 0 for negative inputs.
|
||||
// This seems to be fixed in VS 2019.
|
||||
#if EIGEN_HAS_CXX11_MATH && (!EIGEN_COMP_MSVC || EIGEN_COMP_MSVC >= 1920)
|
||||
#if (!EIGEN_COMP_MSVC || EIGEN_COMP_MSVC >= 1920)
|
||||
// std::arg is only defined for types of std::complex, or integer types or float/double/long double
|
||||
template<typename Scalar,
|
||||
bool HasStdImpl = NumTraits<Scalar>::IsComplex || is_integral<Scalar>::value
|
||||
@ -728,11 +664,7 @@ struct expm1_impl {
|
||||
EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
using std::expm1;
|
||||
#else
|
||||
using std_fallback::expm1;
|
||||
#endif
|
||||
return expm1(x);
|
||||
}
|
||||
};
|
||||
@ -793,11 +725,7 @@ struct log1p_impl {
|
||||
|
||||
EIGEN_DEVICE_FUNC static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
using std::log1p;
|
||||
#else
|
||||
using std_fallback::log1p;
|
||||
#endif
|
||||
return log1p(x);
|
||||
}
|
||||
};
|
||||
@ -1011,7 +939,7 @@ inline EIGEN_MATHFUNC_RETVAL(random, Scalar) random()
|
||||
// Implementation of is* functions
|
||||
|
||||
// std::is* do not work with fast-math and gcc, std::is* are available on MSVC 2013 and newer, as well as in clang.
|
||||
#if (EIGEN_HAS_CXX11_MATH && !(EIGEN_COMP_GNUC_STRICT && __FINITE_MATH_ONLY__)) || (EIGEN_COMP_MSVC) || (EIGEN_COMP_CLANG)
|
||||
#if (!(EIGEN_COMP_GNUC_STRICT && __FINITE_MATH_ONLY__)) || (EIGEN_COMP_MSVC) || (EIGEN_COMP_CLANG)
|
||||
#define EIGEN_USE_STD_FPCLASSIFY 1
|
||||
#else
|
||||
#define EIGEN_USE_STD_FPCLASSIFY 0
|
||||
@ -1721,14 +1649,12 @@ T acos(const T &x) {
|
||||
return acos(x);
|
||||
}
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
T acosh(const T &x) {
|
||||
EIGEN_USING_STD(acosh);
|
||||
return static_cast<T>(acosh(x));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SYCL_DEVICE_ONLY)
|
||||
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(acos, acos)
|
||||
@ -1750,14 +1676,12 @@ T asin(const T &x) {
|
||||
return asin(x);
|
||||
}
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
T asinh(const T &x) {
|
||||
EIGEN_USING_STD(asinh);
|
||||
return static_cast<T>(asinh(x));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SYCL_DEVICE_ONLY)
|
||||
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(asin, asin)
|
||||
@ -1779,14 +1703,12 @@ T atan(const T &x) {
|
||||
return static_cast<T>(atan(x));
|
||||
}
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
template<typename T>
|
||||
EIGEN_DEVICE_FUNC EIGEN_ALWAYS_INLINE
|
||||
T atanh(const T &x) {
|
||||
EIGEN_USING_STD(atanh);
|
||||
return static_cast<T>(atanh(x));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SYCL_DEVICE_ONLY)
|
||||
SYCL_SPECIALIZE_FLOATING_TYPES_UNARY(atan, atan)
|
||||
|
@ -482,11 +482,9 @@ template<typename Derived> class MatrixBase
|
||||
const MatrixFunctionReturnValue<Derived> matrixFunction(StemFunction f) const;
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cosh, hyperbolic cosine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sinh, hyperbolic sine)
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, atanh, inverse hyperbolic cosine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, acosh, inverse hyperbolic cosine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, asinh, inverse hyperbolic sine)
|
||||
#endif
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, cos, cosine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixFunctionReturnValue, sin, sine)
|
||||
EIGEN_MATRIX_FUNCTION(MatrixSquareRootReturnValue, sqrt, square root)
|
||||
|
@ -656,7 +656,6 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 cosh(const bfloat16& a) {
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 tanh(const bfloat16& a) {
|
||||
return bfloat16(::tanhf(float(a)));
|
||||
}
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 asinh(const bfloat16& a) {
|
||||
return bfloat16(::asinhf(float(a)));
|
||||
}
|
||||
@ -666,7 +665,6 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 acosh(const bfloat16& a) {
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 atanh(const bfloat16& a) {
|
||||
return bfloat16(::atanhf(float(a)));
|
||||
}
|
||||
#endif
|
||||
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 floor(const bfloat16& a) {
|
||||
return bfloat16(::floorf(float(a)));
|
||||
}
|
||||
|
@ -593,7 +593,6 @@ struct functor_traits<scalar_tanh_op<Scalar> > {
|
||||
};
|
||||
};
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
/** \internal
|
||||
* \brief Template functor to compute the atanh of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::atanh()
|
||||
@ -607,7 +606,6 @@ template <typename Scalar>
|
||||
struct functor_traits<scalar_atanh_op<Scalar> > {
|
||||
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
|
||||
};
|
||||
#endif
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the sinh of a scalar
|
||||
@ -627,7 +625,6 @@ struct functor_traits<scalar_sinh_op<Scalar> >
|
||||
};
|
||||
};
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
/** \internal
|
||||
* \brief Template functor to compute the asinh of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::asinh()
|
||||
@ -641,7 +638,6 @@ template <typename Scalar>
|
||||
struct functor_traits<scalar_asinh_op<Scalar> > {
|
||||
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
|
||||
};
|
||||
#endif
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the cosh of a scalar
|
||||
@ -661,7 +657,6 @@ struct functor_traits<scalar_cosh_op<Scalar> >
|
||||
};
|
||||
};
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
/** \internal
|
||||
* \brief Template functor to compute the acosh of a scalar
|
||||
* \sa class CwiseUnaryOp, ArrayBase::acosh()
|
||||
@ -675,7 +670,6 @@ template <typename Scalar>
|
||||
struct functor_traits<scalar_acosh_op<Scalar> > {
|
||||
enum { Cost = 5 * NumTraits<Scalar>::MulCost, PacketAccess = false };
|
||||
};
|
||||
#endif
|
||||
|
||||
/** \internal
|
||||
* \brief Template functor to compute the inverse of a scalar
|
||||
|
@ -709,16 +709,6 @@
|
||||
|
||||
#define EIGEN_CONSTEXPR constexpr
|
||||
|
||||
// Does the compiler support C++11 math?
|
||||
// Let's be conservative and enable the default C++11 implementation only if we are sure it exists
|
||||
#ifndef EIGEN_HAS_CXX11_MATH
|
||||
#if (EIGEN_ARCH_i386_OR_x86_64 && (EIGEN_OS_GNULINUX || EIGEN_OS_WIN_STRICT || EIGEN_OS_MAC))
|
||||
#define EIGEN_HAS_CXX11_MATH 1
|
||||
#else
|
||||
#define EIGEN_HAS_CXX11_MATH 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// NOTE: the required Apple's clang version is very conservative
|
||||
// and it could be that XCode 9 works just fine.
|
||||
// NOTE: the MSVC version is based on https://en.cppreference.com/w/cpp/compiler_support
|
||||
|
@ -24,11 +24,9 @@ typedef CwiseUnaryOp<internal::scalar_atan_op<Scalar>, const Derived> AtanReturn
|
||||
typedef CwiseUnaryOp<internal::scalar_tanh_op<Scalar>, const Derived> TanhReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_logistic_op<Scalar>, const Derived> LogisticReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_sinh_op<Scalar>, const Derived> SinhReturnType;
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
typedef CwiseUnaryOp<internal::scalar_atanh_op<Scalar>, const Derived> AtanhReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_asinh_op<Scalar>, const Derived> AsinhReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_acosh_op<Scalar>, const Derived> AcoshReturnType;
|
||||
#endif
|
||||
typedef CwiseUnaryOp<internal::scalar_cosh_op<Scalar>, const Derived> CoshReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_square_op<Scalar>, const Derived> SquareReturnType;
|
||||
typedef CwiseUnaryOp<internal::scalar_cube_op<Scalar>, const Derived> CubeReturnType;
|
||||
@ -355,7 +353,6 @@ cosh() const
|
||||
return CoshReturnType(derived());
|
||||
}
|
||||
|
||||
#if EIGEN_HAS_CXX11_MATH
|
||||
/** \returns an expression of the coefficient-wise inverse hyperbolic tan of *this.
|
||||
*
|
||||
* \sa <a href="group__CoeffwiseMathFunctions.html#cwisetable_atanh">Math functions</a>, atanh(), asinh(), acosh()
|
||||
@ -388,7 +385,6 @@ acosh() const
|
||||
{
|
||||
return AcoshReturnType(derived());
|
||||
}
|
||||
#endif
|
||||
|
||||
/** \returns an expression of the coefficient-wise logistic of *this.
|
||||
*/
|
||||
|
@ -1600,7 +1600,6 @@ PREDEFINED = EIGEN_EMPTY_STRUCT \
|
||||
EIGEN_QT_SUPPORT \
|
||||
EIGEN_STRONG_INLINE=inline \
|
||||
EIGEN_DEVICE_FUNC= \
|
||||
EIGEN_HAS_CXX11_MATH=1 \
|
||||
"EIGEN_MAKE_CWISE_BINARY_OP(METHOD,FUNCTOR)=template<typename OtherDerived> const CwiseBinaryOp<FUNCTOR<Scalar>, const Derived, const OtherDerived> METHOD(const EIGEN_CURRENT_STORAGE_BASE_CLASS<OtherDerived> &other) const;" \
|
||||
"EIGEN_CWISE_PRODUCT_RETURN_TYPE(LHS,RHS)=CwiseBinaryOp<internal::scalar_product_op<LHS::Scalar,RHS::Scalar>, const LHS, const RHS>"\
|
||||
"EIGEN_CAT2(a,b)= a ## b"\
|
||||
|
@ -63,7 +63,6 @@ For instance, one might limit the C++ version to C++14 by defining EIGEN_MAX_CPP
|
||||
functions by defining EIGEN_HAS_C99_MATH=1.
|
||||
|
||||
- \b EIGEN_HAS_C99_MATH - controls the usage of C99 math functions such as erf, erfc, lgamma, etc.
|
||||
- \b EIGEN_HAS_CXX11_MATH - controls the implementation of some functions such as round, logp1, isinf, isnan, etc.
|
||||
- \b EIGEN_HAS_STD_RESULT_OF - defines whether std::result_of is supported
|
||||
- \b EIGEN_NO_IO - Disables any usage and support for `<iostreams>`.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user