Skip to content

Commit d728d42

Browse files
committed
Support scaler tensor
1 parent c52fe48 commit d728d42

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

python/paddle/fluid/tests/unittests/test_var_base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,17 @@ def test_tensor_str3(self):
466466
self.assertEqual(a_str, expected)
467467
paddle.enable_static()
468468

469+
def test_tensor_str_scaler(self):
470+
paddle.disable_static(paddle.CPUPlace())
471+
a = paddle.to_tensor(np.array(False))
472+
a_str = str(a)
473+
474+
expected = '''Tensor(shape=[], dtype=bool, place=CPUPlace, stop_gradient=True,
475+
False)'''
476+
477+
self.assertEqual(a_str, expected)
478+
paddle.enable_static()
479+
469480

470481
class TestVarBaseSetitem(unittest.TestCase):
471482
def setUp(self):

python/paddle/tensor/to_string.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _format_tensor(var, sumary, indent=0, max_width=0, signed=False):
153153
if len(var.shape) == 0:
154154
# currently, shape = [], i.e., scaler tensor is not supported.
155155
# If it is supported, it should be formatted like this.
156-
return _format_item(var.item(0), max_width, signed)
156+
return _format_item(var, max_width, signed)
157157
elif len(var.shape) == 1:
158158
if sumary and var.shape[0] > 2 * edgeitems:
159159
items = [

0 commit comments

Comments
 (0)