[XLA] Add NaN tests for RoundTripFpToString

Specifically, we want to check that NaN values with a sign bit set are appropriately converted.

PiperOrigin-RevId: 335433764
Change-Id: I2c6056645264054819b15e566e0489956147eb6e
This commit is contained in:
David Majnemer 2020-10-05 09:31:15 -07:00 committed by TensorFlower Gardener
parent eaf2c9d3e7
commit f9a73552a6
2 changed files with 24 additions and 0 deletions
tensorflow/compiler/xla

View File

@ -277,6 +277,7 @@ tf_cc_test(
":types",
":util",
"//tensorflow/core:test_main",
"//tensorflow/core/platform:bfloat16",
],
)

View File

@ -15,10 +15,12 @@ limitations under the License.
#include "tensorflow/compiler/xla/util.h"
#include <limits>
#include <list>
#include "tensorflow/compiler/xla/test.h"
#include "tensorflow/compiler/xla/types.h"
#include "tensorflow/core/platform/bfloat16.h"
namespace xla {
namespace {
@ -103,5 +105,26 @@ TEST(UtilTest, SanitizeFileName) {
EXPECT_EQ(SanitizeFileName("/A\\B[C]"), "_A_B_C_");
}
TEST(UtilTest, RoundTripFpToString) {
EXPECT_EQ(RoundTripFpToString(std::numeric_limits<Eigen::half>::quiet_NaN()),
"nan");
EXPECT_EQ(RoundTripFpToString(-std::numeric_limits<Eigen::half>::quiet_NaN()),
"-nan");
EXPECT_EQ(RoundTripFpToString(
std::numeric_limits<tensorflow::bfloat16>::quiet_NaN()),
"nan");
EXPECT_EQ(RoundTripFpToString(
-std::numeric_limits<tensorflow::bfloat16>::quiet_NaN()),
"-nan");
EXPECT_EQ(RoundTripFpToString(std::numeric_limits<float>::quiet_NaN()),
"nan");
EXPECT_EQ(RoundTripFpToString(-std::numeric_limits<float>::quiet_NaN()),
"-nan");
EXPECT_EQ(RoundTripFpToString(std::numeric_limits<double>::quiet_NaN()),
"nan");
EXPECT_EQ(RoundTripFpToString(-std::numeric_limits<double>::quiet_NaN()),
"-nan");
}
} // namespace
} // namespace xla