From dab490a8bfb0cf1f289c9352c4d086356d0e5949 Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 14 Aug 2020 14:25:29 -0700 Subject: [PATCH] Add explicit support for bfloat16 in tensorflow/core/platform/strcat.h PiperOrigin-RevId: 326729760 Change-Id: I36f681b20f91f3c08f4c5b795e488f90d17194aa --- tensorflow/core/platform/strcat.h | 2 ++ tensorflow/core/platform/strcat_test.cc | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/tensorflow/core/platform/strcat.h b/tensorflow/core/platform/strcat.h index 3569a86ab33..752cae148f3 100644 --- a/tensorflow/core/platform/strcat.h +++ b/tensorflow/core/platform/strcat.h @@ -117,6 +117,8 @@ class AlphaNum { : piece_(digits_, FloatToBuffer(f, digits_)) {} AlphaNum(double f) // NOLINT(runtime/explicit) : piece_(digits_, DoubleToBuffer(f, digits_)) {} + AlphaNum(bfloat16 bf) // NOLINT(runtime/explicit) + : piece_(digits_, FloatToBuffer(static_cast(bf), digits_)) {} AlphaNum(Hex hex); // NOLINT(runtime/explicit) diff --git a/tensorflow/core/platform/strcat_test.cc b/tensorflow/core/platform/strcat_test.cc index 0dde19af9c9..6648c716f22 100644 --- a/tensorflow/core/platform/strcat_test.cc +++ b/tensorflow/core/platform/strcat_test.cc @@ -61,6 +61,21 @@ TEST(StrCat, Ints) { EXPECT_EQ(answer, "130"); } +TEST(StrCat, Floats) { + const int s = 0; + const float f = 1.5f; + const double d = 1.5; + const bfloat16 bf(1.5f); + + string answer; + answer = tensorflow::strings::StrCat(s, f); + EXPECT_EQ(answer, "01.5"); + answer = tensorflow::strings::StrCat(s, d); + EXPECT_EQ(answer, "01.5"); + answer = tensorflow::strings::StrCat(s, bf); + EXPECT_EQ(answer, "01.5"); +} + TEST(StrCat, Basics) { string result;