aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Niels Dekker <N.Dekker@lumc.nl>2020-07-11 12:50:46 +0200
committerGravatar Niels Dekker <N.Dekker@lumc.nl>2020-07-11 13:32:28 +0200
commit4ab32e2de2511746e2108563a43cbbeb1922fbf2 (patch)
treea06f6a180f538ce9dfd79138bd7c2efbf5c1e65b /Eigen
parentdcf7655b3d469a399c1182f350c9009e13ad8654 (diff)
Allow implicit conversion from bfloat16 to float and double
Conversion from `bfloat16` to `float` and `double` is lossless. It seems natural to allow the conversion to be implicit, as the C++ language also support implicit conversion from a smaller to a larger floating point type. Intel's OneDLL bfloat16 implementation also has an implicit `operator float()`: https://github.com/oneapi-src/oneDNN/blob/v1.5/src/common/bfloat16.hpp
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/src/Core/arch/Default/BFloat16.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/Eigen/src/Core/arch/Default/BFloat16.h b/Eigen/src/Core/arch/Default/BFloat16.h
index 561304f80..abf2ac933 100644
--- a/Eigen/src/Core/arch/Default/BFloat16.h
+++ b/Eigen/src/Core/arch/Default/BFloat16.h
@@ -117,10 +117,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 EIGEN_EXPLICIT_CAST(float) const {
+ EIGEN_DEVICE_FUNC operator float() const {
return bfloat16_impl::bfloat16_to_float(*this);
}
- EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(double) const {
+ EIGEN_DEVICE_FUNC operator double() const {
return static_cast<double>(bfloat16_impl::bfloat16_to_float(*this));
}
template<typename RealScalar>