Revert change that made conversion from bfloat16 to {float, double} implicit.

Add roundtrip tests for casting between bfloat16 and complex types.
This commit is contained in:
Rasmus Munk Larsen
2020-07-22 18:09:00 -07:00
parent 38b91f256b
commit 1b84f21e32
2 changed files with 26 additions and 15 deletions

View File

@@ -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>