aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen/src/Core/arch/Default/BFloat16.h
diff options
context:
space:
mode:
authorGravatar Rasmus Munk Larsen <rmlarsen@google.com>2020-07-22 18:09:00 -0700
committerGravatar Rasmus Munk Larsen <rmlarsen@google.com>2020-07-22 18:09:00 -0700
commit1b84f21e321e9daa1efcd4422ae92c1782c5582c (patch)
tree949b6adeb3fcf26ff67b47561e754a3bc99e0640 /Eigen/src/Core/arch/Default/BFloat16.h
parent38b91f256be8bf498f0ba9e8dc4fa0abdd7abe70 (diff)
Revert change that made conversion from bfloat16 to {float, double} implicit.
Add roundtrip tests for casting between bfloat16 and complex types.
Diffstat (limited to 'Eigen/src/Core/arch/Default/BFloat16.h')
-rw-r--r--Eigen/src/Core/arch/Default/BFloat16.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/Eigen/src/Core/arch/Default/BFloat16.h b/Eigen/src/Core/arch/Default/BFloat16.h
index f9c6e76a9..30c998249 100644
--- a/Eigen/src/Core/arch/Default/BFloat16.h
+++ b/Eigen/src/Core/arch/Default/BFloat16.h
@@ -34,8 +34,9 @@ namespace Eigen {
struct bfloat16;
-// Since we allow implicit conversion of bfloat16 to float and double, we
-// need to make the cast to complex a bit more explicit
+// explicit conversion operators are no available before C++11 so we first cast
+// bfloat16 to RealScalar rather than to std::complex<RealScalar> directly
+#if !EIGEN_HAS_CXX11
namespace internal {
template <typename RealScalar>
struct cast_impl<bfloat16, std::complex<RealScalar> > {
@@ -45,6 +46,7 @@ struct cast_impl<bfloat16, std::complex<RealScalar> > {
}
};
} // namespace internal
+#endif // EIGEN_HAS_CXX11
namespace bfloat16_impl {
@@ -129,10 +131,10 @@ struct bfloat16 : public bfloat16_impl::bfloat16_base {
EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(unsigned long long) const {
return static_cast<unsigned long long>(bfloat16_to_float(*this));
}
- EIGEN_DEVICE_FUNC operator float() const {
+ EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(float) const {
return bfloat16_impl::bfloat16_to_float(*this);
}
- EIGEN_DEVICE_FUNC operator double() const {
+ EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(double) const {
return static_cast<double>(bfloat16_impl::bfloat16_to_float(*this));
}
template<typename RealScalar>