Browse Source

!4206 Fix Tensor::ToString() data sync problem

Merge pull request !4206 from hewei/fix_tensor_to_string
tags/v0.7.0-beta
mindspore-ci-bot Gitee 5 years ago
parent
commit
a0531b7b41
1 changed files with 2 additions and 0 deletions
  1. +2
    -0
      mindspore/core/ir/tensor.cc

+ 2
- 0
mindspore/core/ir/tensor.cc View File

@@ -465,6 +465,7 @@ std::string Tensor::GetShapeAndDataTypeInfo() const {
std::string Tensor::ToString() const { std::string Tensor::ToString() const {
const int small_tensor_size = 30; const int small_tensor_size = 30;
std::ostringstream buf; std::ostringstream buf;
data_sync();
buf << "Tensor shape:[" << shape() << "]" << this->Dtype()->ToString(); buf << "Tensor shape:[" << shape() << "]" << this->Dtype()->ToString();
// only print small tensor // only print small tensor
if (DataSize() < small_tensor_size) { if (DataSize() < small_tensor_size) {
@@ -477,6 +478,7 @@ std::string Tensor::ToStringRepr() const {
std::ostringstream buf; std::ostringstream buf;
auto type_ptr = this->Dtype(); auto type_ptr = this->Dtype();
MS_EXCEPTION_IF_NULL(type_ptr); MS_EXCEPTION_IF_NULL(type_ptr);
data_sync();
buf << "Tensor shape:[" << shape() << "]" << type_ptr->ToString(); buf << "Tensor shape:[" << shape() << "]" << type_ptr->ToString();
buf << "\nvalue:" << data().ToString(data_type_, shape()); buf << "\nvalue:" << data().ToString(data_type_, shape());
return buf.str(); return buf.str();


Loading…
Cancel
Save