diff --git a/aten/src/ATen/core/DeprecatedTypeProperties.h b/aten/src/ATen/core/DeprecatedTypeProperties.h index ed09ccb8af3..50645b62e5d 100644 --- a/aten/src/ATen/core/DeprecatedTypeProperties.h +++ b/aten/src/ATen/core/DeprecatedTypeProperties.h @@ -64,9 +64,16 @@ class CAFFE2_API DeprecatedTypeProperties { } std::string toString() const { - std::stringstream ss; - ss << at::toString(backend()) << at::toString(scalarType()) << "Type"; - return ss.str(); + std::string base_str; + if (backend_ == Backend::Undefined || scalar_type_ == ScalarType::Undefined) { + base_str = "UndefinedType"; + } else { + base_str = std::string(at::toString(backend_)) + at::toString(scalar_type_) + "Type"; + } + if (is_variable_) { + return "Variable[" + base_str + "]"; + } + return base_str; } DeprecatedTypeProperties & toBackend(Backend b) const { diff --git a/aten/src/ATen/core/Tensor.cpp b/aten/src/ATen/core/Tensor.cpp index aa611e87454..4597432cf17 100644 --- a/aten/src/ATen/core/Tensor.cpp +++ b/aten/src/ATen/core/Tensor.cpp @@ -35,14 +35,14 @@ void Tensor::enforce_invariants() { void Tensor::print() const { if (defined()) { - std::cerr << "[" << dispatch_type().toString() << " " << sizes() << "]" << std::endl; + std::cerr << "[" << type().toString() << " " << sizes() << "]" << std::endl; } else { std::cerr << "[UndefinedTensor]" << std::endl; } } -const char * Tensor::toString() const { - return dispatch_type().toString(); +std::string Tensor::toString() const { + return type().toString(); } } // namespace at diff --git a/aten/src/ATen/core/Tensor.h b/aten/src/ATen/core/Tensor.h index 93812524b48..8adfd7ab5ed 100644 --- a/aten/src/ATen/core/Tensor.h +++ b/aten/src/ATen/core/Tensor.h @@ -154,7 +154,7 @@ class CAFFE2_API Tensor { return impl_.weak_use_count(); } - const char * toString() const; + std::string toString() const; IntArrayRef sizes() const { return impl_->sizes(); diff --git a/aten/src/ATen/templates/Tensor.h b/aten/src/ATen/templates/Tensor.h index a8af9e154fd..1e669c5dbfd 100644 --- a/aten/src/ATen/templates/Tensor.h +++ b/aten/src/ATen/templates/Tensor.h @@ -154,7 +154,7 @@ class CAFFE2_API Tensor { return impl_.weak_use_count(); } - const char * toString() const; + std::string toString() const; IntArrayRef sizes() const { return impl_->sizes(); diff --git a/test/expect/TestScript.test_print-stdout.expect b/test/expect/TestScript.test_print-stdout.expect index 0131b4bcc52..f4449c73b84 100644 --- a/test/expect/TestScript.test_print-stdout.expect +++ b/test/expect/TestScript.test_print-stdout.expect @@ -2,4 +2,4 @@ 0.9526 0.9975 0.9999 -[ Variable[CPUType]{4} ] 1 2 [1, 2] [1., 2.] +[ Variable[CPUDoubleType]{4} ] 1 2 [1, 2] [1., 2.] diff --git a/test/expect/TestScript.test_string_print-stdout.expect b/test/expect/TestScript.test_string_print-stdout.expect index c8a75f4ca84..19f670510f1 100644 --- a/test/expect/TestScript.test_string_print-stdout.expect +++ b/test/expect/TestScript.test_string_print-stdout.expect @@ -1,2 +1,2 @@ 1 -[ Variable[CPUType]{} ] abcd 2 1.5 +[ Variable[CPULongType]{} ] abcd 2 1.5