Skip to content
This repository was archived by the owner on Jan 26, 2026. It is now read-only.

Commit 7babf97

Browse files
committed
improving tensor print formating
1 parent 5b07b3e commit 7babf97

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/DDPTensorImpl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ std::string DDPTensorImpl::__repr__() const
9595
const auto nd = ndims();
9696
std::ostringstream oss;
9797
oss << "ddptensor{gs=(";
98-
for(auto i=0; i<nd; ++i) oss << _gs_aligned[i] << ", ";
98+
for(auto i=0; i<nd; ++i) oss << _gs_aligned[i] << (i==nd-1 ? "" : ", ");
9999
oss << "), loff=(";
100-
for(auto i=0; i<nd; ++i) oss << _lo_aligned[i] << ", ";
100+
for(auto i=0; i<nd; ++i) oss << _lo_aligned[i] << (i==nd-1 ? "" : ", ");
101101
oss << "), lsz=(";
102-
for(auto i=0; i<nd; ++i) oss << _sizes[i] << ", ";
102+
for(auto i=0; i<nd; ++i) oss << _sizes[i] << (i==nd-1 ? "" : ", ");
103103
oss << "), str=(";
104-
for(auto i=0; i<nd; ++i) oss << _strides[i] << ", ";
104+
for(auto i=0; i<nd; ++i) oss << _strides[i] << (i==nd-1 ? "" : ", ");
105105
oss << "), p=" << _allocated << ", poff=" << _offset << "}\n";
106106

107107
dispatch(_dtype, _aligned, [this, nd, &oss](auto * ptr) {

src/include/ddptensor/DDPTensorImpl.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,13 @@ class DDPTensorImpl : public tensor_i
153153
if(d==ndims()-1) {
154154
oss << "[";
155155
for(auto i=0; i<sz; ++i) {
156-
oss << cptr[i*stride];
157-
if(i<sz-1) oss << " ";
156+
oss << cptr[i*stride] << (i<sz-1 ? " " : "");
158157
}
159158
oss << "]";
160159
} else {
161160
oss << "[";
162161
for(auto i=0; i<sz; ++i) {
163-
if(i) for(auto x=0; x<=d; ++x) oss << " ";
162+
if(i) oss << std::string(d+1, ' ');
164163
printit(oss, d+1, cptr);
165164
if(i<sz-1) oss << "\n";
166165
cptr += stride;

0 commit comments

Comments
 (0)