mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-28 06:44:10 +08:00
Remove explicit casts from Eigen::half and Eigen::bfloat16 to bool
Both, Eigen::half and Eigen::Bfloat16 are implicitly convertible to float and can hence be converted to bool via the conversion chain Eigen::{half,bfloat16} -> float -> bool We thus remove the explicit cast operator to bool.
This commit is contained in:
parent
a8fdcae55d
commit
6c9c3f9a1a
@ -82,14 +82,6 @@ struct bfloat16 : public bfloat16_impl::bfloat16_base {
|
||||
EIGEN_DEVICE_FUNC operator float() const { // NOLINT: Allow implicit conversion to float, because it is lossless.
|
||||
return bfloat16_impl::bfloat16_to_float(*this);
|
||||
}
|
||||
|
||||
#if EIGEN_HAS_CXX11
|
||||
EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(bool) const {
|
||||
// +0.0 and -0.0 become false, everything else becomes true.
|
||||
return (value & 0x7fff) != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
||||
} // namespace Eigen
|
||||
|
||||
|
@ -162,15 +162,6 @@ struct half : public half_impl::half_base {
|
||||
EIGEN_DEVICE_FUNC operator float() const { // NOLINT: Allow implicit conversion to float, because it is lossless.
|
||||
return half_impl::half_to_float(*this);
|
||||
}
|
||||
|
||||
EIGEN_DEVICE_FUNC EIGEN_EXPLICIT_CAST(bool) const {
|
||||
// +0.0 and -0.0 become false, everything else becomes true.
|
||||
#if defined(EIGEN_HAS_ARM64_FP16_SCALAR_ARITHMETIC)
|
||||
return (numext::bit_cast<numext::uint16_t>(x) & 0x7fff) != 0;
|
||||
#else
|
||||
return (x & 0x7fff) != 0;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
} // end namespace Eigen
|
||||
|
Loading…
x
Reference in New Issue
Block a user