Add scalar type info to tensor print (#20483)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/20483
ghimport-source-id: 31bfc51af1060e83492315b96884fc725a1eb84f

Differential Revision: D15334010

Pulled By: li-roy

fbshipit-source-id: 199b575855146a7336d57c165191a16e7e1b5785
This commit is contained in:
Roy Li 2019-05-15 18:57:48 -07:00 committed by Facebook Github Bot
parent abb3698976
commit 51e40ab832
6 changed files with 17 additions and 10 deletions

View File

@ -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 {

View File

@ -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

View File

@ -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();

View File

@ -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();

View File

@ -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.]

View File

@ -1,2 +1,2 @@
1
[ Variable[CPUType]{} ] abcd 2 1.5
[ Variable[CPULongType]{} ] abcd 2 1.5