From 2aa35759ddf5a3079a455cdb06a4dd1e5e3b622f Mon Sep 17 00:00:00 2001 From: Zhang Qinghua Date: Sat, 25 Jul 2020 10:10:55 +0800 Subject: [PATCH] Set the width of different int type for printing Tensor data. --- mindspore/core/ir/tensor.cc | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mindspore/core/ir/tensor.cc b/mindspore/core/ir/tensor.cc index 2fc75b6755..c7f3b8fce8 100644 --- a/mindspore/core/ir/tensor.cc +++ b/mindspore/core/ir/tensor.cc @@ -224,10 +224,21 @@ class TensorDataImpl : public TensorData { ss << ' '; } } + + // Set width and indent for different int type. + // + // int8/uint8 width: 3 + // int16/uint16 width: 5 + // int32/uint32 width: 10 + // int64/uint64 width: NOT SET if constexpr (std::is_same::value) { - ss << static_cast(value); + ss << std::setw(3) << std::setiosflags(std::ios::right) << static_cast(value); } else if constexpr (std::is_same::value) { - ss << static_cast(value); + ss << std::setw(3) << std::setiosflags(std::ios::right) << static_cast(value); + } else if constexpr (std::is_same::value || std::is_same::value) { + ss << std::setw(5) << std::setiosflags(std::ios::right) << value; + } else if constexpr (std::is_same::value || std::is_same::value) { + ss << std::setw(10) << std::setiosflags(std::ios::right) << value; } else { ss << value; }