Skip to content

Commit

Permalink
Add implicit F8 conversions
Browse files Browse the repository at this point in the history
Adds implicit conversions between F8 types and `float`, `half`, and `bfloat16`. This allows using the `std` math functions for the F8 types as easy as if they were `float` or `bfloat16`. Note that `bfloat16` already has an implicit conversion to `float`, so it already has good ergonomics.

PiperOrigin-RevId: 663402572
  • Loading branch information
Gregory Pataky authored and The ml_dtypes Authors committed Aug 29, 2024
1 parent 82f3a61 commit 407205c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ml_dtypes/include/float8.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ class float8_base {
explicit EIGEN_DEVICE_FUNC operator double() const {
return ConvertTo<double>(derived());
}
explicit EIGEN_DEVICE_FUNC operator float() const {
EIGEN_DEVICE_FUNC operator float() const {
return ConvertTo<float>(derived());
}
explicit EIGEN_DEVICE_FUNC operator Eigen::bfloat16() const {
EIGEN_DEVICE_FUNC operator Eigen::bfloat16() const {
return ConvertTo<Eigen::bfloat16>(derived());
}
explicit EIGEN_DEVICE_FUNC operator Eigen::half() const {
EIGEN_DEVICE_FUNC operator Eigen::half() const {
return ConvertTo<Eigen::half>(derived());
}
explicit EIGEN_DEVICE_FUNC operator bool() const {
Expand Down

0 comments on commit 407205c

Please sign in to comment.