Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions python/paddle/fluid/tests/unittests/test_var_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,17 @@ def test_tensor_str3(self):
self.assertEqual(a_str, expected)
paddle.enable_static()

def test_tensor_str_scaler(self):
paddle.disable_static(paddle.CPUPlace())
a = paddle.to_tensor(np.array(False))
a_str = str(a)

expected = '''Tensor(shape=[], dtype=bool, place=CPUPlace, stop_gradient=True,
False)'''

self.assertEqual(a_str, expected)
paddle.enable_static()


class TestVarBaseSetitem(unittest.TestCase):
def setUp(self):
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/tensor/to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _format_tensor(var, sumary, indent=0, max_width=0, signed=False):
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.item(0), max_width, signed)
return _format_item(var, max_width, signed)
elif len(var.shape) == 1:
if sumary and var.shape[0] > 2 * edgeitems:
items = [
Expand Down