Skip to content

Commit 77660a9

Browse files
authored
Support printing sparse tensors in ATen, fixes #8333. (#8334)
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
1 parent 77dea37 commit 77660a9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

aten/src/ATen/Formatting.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ std::ostream& print(std::ostream& stream, const Tensor & tensor_, int64_t linesi
247247
FormatGuard guard(stream);
248248
if(!tensor_.defined()) {
249249
stream << "[ Tensor (undefined) ]";
250+
} else if (tensor_.is_sparse()) {
251+
stream << "[ " << tensor_.pImpl->toString() << "{}\n";
252+
stream << "indices:\n" << tensor_._indices() << "\n";
253+
stream << "values:\n" << tensor_._values() << "\n";
254+
stream << "size:\n" << tensor_.sizes() << "\n";
255+
stream << "]";
250256
} else {
251257
Type& cpudouble = tensor_.type().toBackend(kCPU).toScalarType(kDouble);
252258
Tensor tensor = tensor_.toType(cpudouble).contiguous();

0 commit comments

Comments
 (0)