Protect against compilation errors with nvcc and numext/complex.

Disable functions explicitely involving std::complex when compiling with nvcc.
Improve code compatilibity using the new macro EIGEN_USING_NUMEXT_MATH (same spirit than EIGEN_USING_STD_MATH but for numext functions)
This commit is contained in:
Nicolas Mellado 2015-07-06 20:55:01 +02:00
parent c2019dfeb3
commit 5359e5cdb2
4 changed files with 66 additions and 35 deletions

View File

@ -42,6 +42,12 @@
#define EIGEN_USING_STD_MATH(FUNC) using std::FUNC;
#endif
#if defined(__CUDA_ARCH__)
#define EIGEN_USING_NUMEXT_MATH(FUNC) using ::FUNC;
#else
#define EIGEN_USING_NUMEXT_MATH(FUNC) using numext::FUNC;
#endif
#if (defined(_CPPUNWIND) || defined(__EXCEPTIONS)) && !defined(__CUDA_ARCH__) && !defined(EIGEN_EXCEPTIONS)
#define EIGEN_EXCEPTIONS
#endif

View File

@ -62,9 +62,11 @@ namespace Eigen
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(round,scalar_round_op)
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(floor,scalar_floor_op)
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(ceil,scalar_ceil_op)
#ifndef __CUDACC__
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isnan,scalar_isnan_op)
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isinf,scalar_isinf_op)
EIGEN_ARRAY_DECLARE_GLOBAL_UNARY(isfinite,scalar_isfinite_op)
#endif
template<typename Derived>
inline const Eigen::CwiseUnaryOp<Eigen::internal::scalar_pow_op<typename Derived::Scalar>, const Derived>

View File

@ -279,7 +279,7 @@ struct norm1_default_impl
EIGEN_DEVICE_FUNC
static inline RealScalar run(const Scalar& x)
{
using std::abs;
EIGEN_USING_STD_MATH(abs);
return abs(real(x)) + abs(imag(x));
}
};
@ -290,7 +290,7 @@ struct norm1_default_impl<Scalar, false>
EIGEN_DEVICE_FUNC
static inline Scalar run(const Scalar& x)
{
using std::abs;
EIGEN_USING_STD_MATH(abs);
return abs(x);
}
};
@ -316,8 +316,8 @@ struct hypot_impl
{
EIGEN_USING_STD_MATH(max);
EIGEN_USING_STD_MATH(min);
using std::abs;
using std::sqrt;
EIGEN_USING_STD_MATH(abs);
EIGEN_USING_STD_MATH(sqrt);
RealScalar _x = abs(x);
RealScalar _y = abs(y);
Scalar p, qp;
@ -386,8 +386,8 @@ inline NewType cast(const OldType& x)
static inline Scalar run(const Scalar& x)
{
EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
using std::floor;
using std::ceil;
EIGEN_USING_STD_MATH(floor);
EIGEN_USING_STD_MATH(ceil);
return (x > 0.0) ? floor(x + 0.5) : ceil(x - 0.5);
}
};
@ -408,7 +408,7 @@ struct round_retval
struct arg_impl {
static inline Scalar run(const Scalar& x)
{
using std::arg;
EIGEN_USING_STD_MATH(arg);
return arg(x);
}
};
@ -430,7 +430,7 @@ struct round_retval
EIGEN_DEVICE_FUNC
static inline RealScalar run(const Scalar& x)
{
using std::arg;
EIGEN_USING_STD_MATH(arg);
return arg(x);
}
};
@ -454,7 +454,7 @@ struct log1p_impl
{
EIGEN_STATIC_ASSERT_NON_INTEGER(Scalar)
typedef typename NumTraits<Scalar>::Real RealScalar;
using std::log;
EIGEN_USING_STD_MATH(log);
Scalar x1p = RealScalar(1) + x;
return ( x1p == Scalar(1) ) ? x : x * ( log(x1p) / (x1p - RealScalar(1)) );
}
@ -488,7 +488,7 @@ struct pow_default_impl
typedef Scalar retval;
static inline Scalar run(const Scalar& x, const Scalar& y)
{
using std::pow;
EIGEN_USING_STD_MATH(pow);
return pow(x, y);
}
};
@ -794,13 +794,26 @@ bool (isfinite)(const T& x)
#endif
}
#ifndef __CUDACC__
template<typename T>
EIGEN_DEVICE_FUNC
bool (isfinite)(const std::complex<T>& x)
{
return numext::isfinite(numext::real(x)) && numext::isfinite(numext::imag(x));
}
template<typename T>
bool (isnan)(const std::complex<T>& x)
{
return numext::isnan(numext::real(x)) || numext::isnan(numext::imag(x));
}
template<typename T>
bool (isinf)(const std::complex<T>& x)
{
return (numext::isinf(numext::real(x)) || numext::isinf(numext::imag(x))) && (!numext::isnan(x));
}
#endif
template<typename T>
EIGEN_DEVICE_FUNC
bool (isnan)(const T& x)
@ -813,13 +826,6 @@ bool (isnan)(const T& x)
#endif
}
template<typename T>
EIGEN_DEVICE_FUNC
bool (isnan)(const std::complex<T>& x)
{
return numext::isnan(numext::real(x)) || numext::isnan(numext::imag(x));
}
template<typename T>
EIGEN_DEVICE_FUNC
bool (isinf)(const T& x)
@ -832,13 +838,6 @@ bool (isinf)(const T& x)
#endif
}
template<typename T>
EIGEN_DEVICE_FUNC
bool (isinf)(const std::complex<T>& x)
{
return (numext::isinf(numext::real(x)) || numext::isinf(numext::imag(x))) && (!numext::isnan(x));
}
template<typename Scalar>
EIGEN_DEVICE_FUNC
inline EIGEN_MATHFUNC_RETVAL(round, Scalar) round(const Scalar& x)
@ -850,7 +849,7 @@ template<typename T>
EIGEN_DEVICE_FUNC
T (floor)(const T& x)
{
using std::floor;
EIGEN_USING_STD_MATH(floor);
return floor(x);
}
@ -858,7 +857,7 @@ template<typename T>
EIGEN_DEVICE_FUNC
T (ceil)(const T& x)
{
using std::ceil;
EIGEN_USING_STD_MATH(ceil);
return ceil(x);
}
@ -897,14 +896,14 @@ struct scalar_fuzzy_default_impl<Scalar, false, false>
template<typename OtherScalar> EIGEN_DEVICE_FUNC
static inline bool isMuchSmallerThan(const Scalar& x, const OtherScalar& y, const RealScalar& prec)
{
using std::abs;
EIGEN_USING_STD_MATH(abs);
return abs(x) <= abs(y) * prec;
}
EIGEN_DEVICE_FUNC
static inline bool isApprox(const Scalar& x, const Scalar& y, const RealScalar& prec)
{
EIGEN_USING_STD_MATH(min);
using std::abs;
EIGEN_USING_STD_MATH(abs);
return abs(x - y) <= (min)(abs(x), abs(y)) * prec;
}
EIGEN_DEVICE_FUNC

View File

@ -533,7 +533,11 @@ struct functor_traits<scalar_cube_op<Scalar> >
*/
template<typename Scalar> struct scalar_round_op {
EIGEN_EMPTY_STRUCT_CTOR(scalar_round_op)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { using numext::round; return round(a); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const
{
EIGEN_USING_NUMEXT_MATH(round);
return round(a);
}
typedef typename packet_traits<Scalar>::type Packet;
inline Packet packetOp(const Packet& a) const { return internal::pround(a); }
};
@ -552,7 +556,11 @@ struct functor_traits<scalar_round_op<Scalar> >
*/
template<typename Scalar> struct scalar_floor_op {
EIGEN_EMPTY_STRUCT_CTOR(scalar_floor_op)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::floor(a); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const
{
EIGEN_USING_NUMEXT_MATH(floor);
return floor(a);
}
typedef typename packet_traits<Scalar>::type Packet;
inline Packet packetOp(const Packet& a) const { return internal::pfloor(a); }
};
@ -571,7 +579,11 @@ struct functor_traits<scalar_floor_op<Scalar> >
*/
template<typename Scalar> struct scalar_ceil_op {
EIGEN_EMPTY_STRUCT_CTOR(scalar_ceil_op)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const { return numext::ceil(a); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (const Scalar& a) const
{
EIGEN_USING_NUMEXT_MATH(ceil);
return ceil(a);
}
typedef typename packet_traits<Scalar>::type Packet;
inline Packet packetOp(const Packet& a) const { return internal::pceil(a); }
};
@ -591,7 +603,11 @@ struct functor_traits<scalar_ceil_op<Scalar> >
template<typename Scalar> struct scalar_isnan_op {
EIGEN_EMPTY_STRUCT_CTOR(scalar_isnan_op)
typedef bool result_type;
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::isnan(a); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const
{
EIGEN_USING_NUMEXT_MATH(isnan);
return isnan(a);
}
};
template<typename Scalar>
struct functor_traits<scalar_isnan_op<Scalar> >
@ -609,7 +625,11 @@ struct functor_traits<scalar_isnan_op<Scalar> >
template<typename Scalar> struct scalar_isinf_op {
EIGEN_EMPTY_STRUCT_CTOR(scalar_isinf_op)
typedef bool result_type;
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::isinf(a); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const
{
EIGEN_USING_NUMEXT_MATH(isinf);
return isinf(a);
}
};
template<typename Scalar>
struct functor_traits<scalar_isinf_op<Scalar> >
@ -627,7 +647,11 @@ struct functor_traits<scalar_isinf_op<Scalar> >
template<typename Scalar> struct scalar_isfinite_op {
EIGEN_EMPTY_STRUCT_CTOR(scalar_isfinite_op)
typedef bool result_type;
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const { return numext::isfinite(a); }
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE result_type operator() (const Scalar& a) const
{
EIGEN_USING_NUMEXT_MATH(isfinite);
return isfinite(a);
}
};
template<typename Scalar>
struct functor_traits<scalar_isfinite_op<Scalar> >