From 3521f9e6223912fbb400c460cde9a250a47c3afe Mon Sep 17 00:00:00 2001 From: He Wei Date: Wed, 19 Aug 2020 11:16:48 +0800 Subject: [PATCH] Fix tensor print format Avoid line feed when printing tensor with 0 or 1 dimension. --- mindspore/core/ir/tensor.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mindspore/core/ir/tensor.cc b/mindspore/core/ir/tensor.cc index 59ccf4509f..efffc2ba26 100644 --- a/mindspore/core/ir/tensor.cc +++ b/mindspore/core/ir/tensor.cc @@ -485,12 +485,12 @@ std::string Tensor::ToString() const { auto dtype = Dtype(); MS_EXCEPTION_IF_NULL(dtype); data_sync(); - buf << "Tensor(shape=" << ShapeToString(shape_) << ", dtype=" << dtype->ToString() << ",\n"; + buf << "Tensor(shape=" << ShapeToString(shape_) << ", dtype=" << dtype->ToString() << ','; if (DataSize() < small_tensor_size) { // Only print data for small tensor. - buf << data().ToString(data_type_, shape_) << ')'; + buf << ((data().ndim() > 1) ? '\n' : ' ') << data().ToString(data_type_, shape_) << ')'; } else { - buf << "[...])"; + buf << " [...])"; } return buf.str(); } @@ -500,8 +500,8 @@ std::string Tensor::ToStringRepr() const { auto dtype = Dtype(); MS_EXCEPTION_IF_NULL(dtype); data_sync(); - buf << "Tensor(shape=" << ShapeToString(shape_) << ", dtype=" << dtype->ToString() << ",\n" - << data().ToString(data_type_, shape_) << ')'; + buf << "Tensor(shape=" << ShapeToString(shape_) << ", dtype=" << dtype->ToString() << ',' + << ((data().ndim() > 1) ? '\n' : ' ') << data().ToString(data_type_, shape_) << ')'; return buf.str(); }