提交 213eacbd 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!4728 Fix tensor print format

Merge pull request !4728 from hewei/fix_tensor_to_string
...@@ -485,12 +485,12 @@ std::string Tensor::ToString() const { ...@@ -485,12 +485,12 @@ std::string Tensor::ToString() const {
auto dtype = Dtype(); auto dtype = Dtype();
MS_EXCEPTION_IF_NULL(dtype); MS_EXCEPTION_IF_NULL(dtype);
data_sync(); data_sync();
buf << "Tensor(shape=" << ShapeToString(shape_) << ", dtype=" << dtype->ToString() << ",\n"; buf << "Tensor(shape=" << ShapeToString(shape_) << ", dtype=" << dtype->ToString() << ',';
if (DataSize() < small_tensor_size) { if (DataSize() < small_tensor_size) {
// Only print data for small tensor. // Only print data for small tensor.
buf << data().ToString(data_type_, shape_) << ')'; buf << ((data().ndim() > 1) ? '\n' : ' ') << data().ToString(data_type_, shape_) << ')';
} else { } else {
buf << "[...])"; buf << " [...])";
} }
return buf.str(); return buf.str();
} }
...@@ -500,8 +500,8 @@ std::string Tensor::ToStringRepr() const { ...@@ -500,8 +500,8 @@ std::string Tensor::ToStringRepr() const {
auto dtype = Dtype(); auto dtype = Dtype();
MS_EXCEPTION_IF_NULL(dtype); MS_EXCEPTION_IF_NULL(dtype);
data_sync(); data_sync();
buf << "Tensor(shape=" << ShapeToString(shape_) << ", dtype=" << dtype->ToString() << ",\n" buf << "Tensor(shape=" << ShapeToString(shape_) << ", dtype=" << dtype->ToString() << ','
<< data().ToString(data_type_, shape_) << ')'; << ((data().ndim() > 1) ? '\n' : ' ') << data().ToString(data_type_, shape_) << ')';
return buf.str(); return buf.str();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册