Skip to content

Commit

Permalink
refine code
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiqiu committed Aug 26, 2021
1 parent a3ebd3b commit 2f3852b
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions python/paddle/tensor/to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _to_summary(var):
if var.shape[0] > 2 * edgeitems:
begin = [x for x in var[:edgeitems]]
end = [x for x in var[(-1 * edgeitems):]]
return np.stack([_to_sumary(x) for x in (begin + end)])
return np.stack([_to_summary(x) for x in (begin + end)])
else:
return np.stack([_to_summary(x) for x in var])

Expand Down Expand Up @@ -168,17 +168,17 @@ def _format_tensor(var, summary, indent=0, max_width=0, signed=False):
signed(bool): Print +/- or not.
"""
edgeitems = DEFAULT_PRINT_OPTIONS.edgeitems
linewidth = DEFAULT_PRINT_OPTIONS.linewidth

if len(var.shape) == 0:
# currently, shape = [], i.e., scaler tensor is not supported.
# If it is supported, it should be formatted like this.
return _format_item(var, max_width, signed)
elif len(var.shape) == 1:
item_length = max_width + 2
items_per_line = (
DEFAULT_PRINT_OPTIONS.linewidth - indent) // item_length
items_per_line = (linewidth - indent) // item_length
items_per_line = max(1, items_per_line)
print(items_per_line)

if summary and var.shape[0] > 2 * edgeitems:
items = [
_format_item(item, max_width, signed)
Expand All @@ -205,13 +205,8 @@ def _format_tensor(var, summary, indent=0, max_width=0, signed=False):
_format_tensor(x, summary, indent + 1, max_width, signed)
for x in var[:edgeitems]
] + ['...'] + [
<<<<<<< HEAD
_format_tensor(x, sumary, indent + 1, max_width, signed)
for x in var[(-1 * edgeitems):]
=======
_format_tensor(x, summary, indent + 1, max_width, signed)
for x in var[-edgeitems:]
>>>>>>> support setting linewith when printing tensor
for x in var[(-1 * edgeitems):]
]
else:
vars = [
Expand Down

0 comments on commit 2f3852b

Please sign in to comment.