diff --git a/Eigen/src/Core/arch/Default/BFloat16.h b/Eigen/src/Core/arch/Default/BFloat16.h index 99ce99a27..561304f80 100644 --- a/Eigen/src/Core/arch/Default/BFloat16.h +++ b/Eigen/src/Core/arch/Default/BFloat16.h @@ -27,6 +27,20 @@ namespace Eigen { struct bfloat16; +// explicit conversion operators are no available before C++11 so we first cast +// bfloat16 to RealScalar rather than to std::complex directly +#if !EIGEN_HAS_CXX11 +namespace internal { +template +struct cast_impl > { + EIGEN_DEVICE_FUNC static inline std::complex run(const bfloat16 &x) + { + return static_cast >(static_cast(x)); + } +}; +} // namespace internal +#endif // EIGEN_HAS_CXX11 + namespace bfloat16_impl { // Make our own __bfloat16_raw definition. diff --git a/Eigen/src/Core/arch/Default/Half.h b/Eigen/src/Core/arch/Default/Half.h index b84cfc7db..bbc15d463 100644 --- a/Eigen/src/Core/arch/Default/Half.h +++ b/Eigen/src/Core/arch/Default/Half.h @@ -36,7 +36,7 @@ #ifndef EIGEN_HALF_H #define EIGEN_HALF_H -#if __cplusplus > 199711L +#if EIGEN_HAS_CXX11 #define EIGEN_EXPLICIT_CAST(tgt_type) explicit operator tgt_type() #else #define EIGEN_EXPLICIT_CAST(tgt_type) operator tgt_type() @@ -48,6 +48,20 @@ namespace Eigen { struct half; +// explicit conversion operators are no available before C++11 so we first cast +// half to RealScalar rather than to std::complex directly +#if !EIGEN_HAS_CXX11 +namespace internal { +template +struct cast_impl > { + EIGEN_DEVICE_FUNC static inline std::complex run(const half &x) + { + return static_cast >(static_cast(x)); + } +}; +} // namespace internal +#endif // EIGEN_HAS_CXX11 + namespace half_impl { #if !defined(EIGEN_HAS_GPU_FP16) @@ -737,7 +751,6 @@ EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC Eigen::half __ldg(const Eigen::half* ptr) } #endif - #if defined(EIGEN_GPU_COMPILE_PHASE) namespace Eigen { namespace numext { diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index 80fc8a07f..f9044a27a 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -195,41 +195,73 @@ template void basicStuffComplex(const MatrixType& m) VERIFY(!static_cast(cm).imag().isZero()); } +template::value || internal::is_same::value)> struct casting_test; + + template -void casting_test() -{ - Matrix m; - for (int i=0; i::value(); +struct casting_test { + static void run() { + Matrix m; + for (int i=0; i::value(); + } + } + Matrix n = m.template cast(); + for (int i=0; i(m(i, j))); + } } } - Matrix n = m.template cast(); - for (int i=0; i(m(i, j))); +}; + +template +struct casting_test { + static void run() { + casting_test::run(); + } +}; + +template +struct casting_test, true> { + static void run() { + typedef std::complex TgtScalar; + Matrix m; + for (int i=0; i::value(); + } + } + Matrix n = m.template cast(); + for (int i=0; i(static_cast(m(i, j)))); + } } } -} +}; template struct casting_test_runner { static void run() { - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test(); - casting_test>(); - casting_test>(); + casting_test::run(); + casting_test::run(); + casting_test::run(); + casting_test::run(); + casting_test::run(); + casting_test::run(); + casting_test::run(); +#if EIGEN_HAS_CXX11 + casting_test::run(); + casting_test::run(); +#endif + casting_test::run(); + casting_test::run(); + casting_test::run(); + casting_test::run(); + casting_test >::run(); + casting_test >::run(); } }; @@ -238,10 +270,10 @@ struct casting_test_runner are defined. - casting_test(); - casting_test(); - casting_test>(); - casting_test>(); + casting_test::run(); + casting_test::run(); + casting_test >::run(); + casting_test >::run(); } }; @@ -253,14 +285,16 @@ void casting_all() { casting_test_runner::run(); casting_test_runner::run(); casting_test_runner::run(); +#if EIGEN_HAS_CXX11 casting_test_runner::run(); casting_test_runner::run(); +#endif casting_test_runner::run(); casting_test_runner::run(); casting_test_runner::run(); casting_test_runner::run(); - casting_test_runner>::run(); - casting_test_runner>::run(); + casting_test_runner >::run(); + casting_test_runner >::run(); } template