From 64bf3df0f97c1d69f1b99f6e4a1a0e6d4059acba Mon Sep 17 00:00:00 2001 From: Kexin Zhao Date: Mon, 16 Apr 2018 19:31:51 -0700 Subject: [PATCH] add print support to float16 (#9960) --- paddle/fluid/platform/float16.h | 5 +++++ paddle/fluid/platform/float16_test.cc | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/paddle/fluid/platform/float16.h b/paddle/fluid/platform/float16.h index 673e1bcae..ffd183af6 100644 --- a/paddle/fluid/platform/float16.h +++ b/paddle/fluid/platform/float16.h @@ -873,6 +873,11 @@ HOSTDEVICE inline bool(isfinite)(const float16& a) { return !((isnan)(a)) && !((isinf)(a)); } +inline std::ostream& operator<<(std::ostream& os, const float16& a) { + os << static_cast(a); + return os; +} + } // namespace platform } // namespace paddle diff --git a/paddle/fluid/platform/float16_test.cc b/paddle/fluid/platform/float16_test.cc index d60aecf96..a589e32b6 100644 --- a/paddle/fluid/platform/float16_test.cc +++ b/paddle/fluid/platform/float16_test.cc @@ -141,5 +141,10 @@ TEST(float16, lod_tensor_cpu) { } } +TEST(float16, print) { + float16 a = float16(1.0f); + std::cout << a << std::endl; +} + } // namespace platform } // namespace paddle -- GitLab