Skip to content

Commit 64bf3df

Browse files
kexinzhaogongweibao
authored andcommitted
add print support to float16 (#9960)
1 parent 5833546 commit 64bf3df

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

paddle/fluid/platform/float16.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ HOSTDEVICE inline bool(isfinite)(const float16& a) {
873873
return !((isnan)(a)) && !((isinf)(a));
874874
}
875875

876+
inline std::ostream& operator<<(std::ostream& os, const float16& a) {
877+
os << static_cast<float>(a);
878+
return os;
879+
}
880+
876881
} // namespace platform
877882
} // namespace paddle
878883

paddle/fluid/platform/float16_test.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,10 @@ TEST(float16, lod_tensor_cpu) {
141141
}
142142
}
143143

144+
TEST(float16, print) {
145+
float16 a = float16(1.0f);
146+
std::cout << a << std::endl;
147+
}
148+
144149
} // namespace platform
145150
} // namespace paddle

0 commit comments

Comments
 (0)