pytorch/c10/util/Float8_e4m3fn.cpp
Gao Tianlin be33d31ae2 add std::ostream& operator<< for BFloat16 in BFloat16.h (#121302)
This PR Move `operator<<` of `BFloat16` to `BFloat16.h`.

Previously, this function is in `TensorDataContainer.h`. If need `std::cout` a `BFloat16` variable when debugging, `TensorDataContainer.h` have to be included. This is inconvient and counterintuitive.

Other dtypes such as `Half`, define their `operator<<` in headers where they are defined such as `Half.h`. Therefore, I think it makes more sense to move `operator<<` of `BFloat16` to `BFloat16.h`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/121302
Approved by: https://github.com/ezyang
2024-03-13 06:47:34 +00:00

15 lines
342 B
C++

#include <c10/util/Float8_e4m3fn.h>
#include <ostream>
#include <type_traits>
namespace c10 {
static_assert(
std::is_standard_layout_v<Float8_e4m3fn>,
"c10::Float8_e4m3fn must be standard layout.");
std::ostream& operator<<(std::ostream& out, const Float8_e4m3fn& value) {
out << (float)value;
return out;
}
} // namespace c10