Skip to content

Commit d6fee25

Browse files
majnemertensorflower-gardener
authored andcommitted
[XLA] Clean up some floating point printing code
- When doing *exact* floating point comparisons, print out enough digits of the floating point number to unambiguously round trip to the float in question. - The exhaustive op test had an off-by-one for precision when printing a float. PiperOrigin-RevId: 277988562 Change-Id: I9d30190a754d698e009fd51aa7fe6ca5661e2bc0
1 parent 34b69b6 commit d6fee25

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tensorflow/compiler/xla/literal_comparison.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
#include "tensorflow/compiler/xla/literal_comparison.h"
1717

1818
#include <unistd.h>
19+
1920
#include <cmath>
2021
#include <vector>
2122

@@ -104,12 +105,12 @@ Status MakeBitwiseErrorStatus(NativeT lhs, NativeT rhs,
104105
auto urhs = absl::bit_cast<UnsignedT>(GetRawValue(rhs));
105106
auto lhs_double = static_cast<double>(lhs);
106107
auto rhs_double = static_cast<double>(rhs);
107-
return InvalidArgument(
108-
"floating values are not bitwise-equal; and equality testing "
109-
"was requested: %s=%g=%a vs %s=%g=%a at array index %s",
110-
StrCat(absl::Hex(ulhs)), lhs_double, lhs_double,
111-
StrCat(absl::Hex(urhs)), rhs_double, rhs_double,
112-
LiteralUtil::MultiIndexAsString(multi_index));
108+
return InvalidArgument(
109+
"floating values are not bitwise-equal; and equality testing "
110+
"was requested: %s=%s=%a vs %s=%s=%a at array index %s",
111+
StrCat(absl::Hex(ulhs)), RoundTripFpToString(lhs), lhs_double,
112+
StrCat(absl::Hex(urhs)), RoundTripFpToString(rhs), rhs_double,
113+
LiteralUtil::MultiIndexAsString(multi_index));
113114
}
114115

115116
template <typename NativeT>

tensorflow/compiler/xla/tests/exhaustive_op_test_utils.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct ComponentStringifyFormat<double> {
3737

3838
template <>
3939
struct ComponentStringifyFormat<float> {
40-
static constexpr absl::string_view value = "%0.8g (0x%08x)";
40+
static constexpr absl::string_view value = "%0.9g (0x%08x)";
4141
};
4242

4343
template <>

0 commit comments

Comments
 (0)