Refine the format of printing tensor 3 (support scaler tensor) (#28544)

musl/fix_failed_unittests_in_musl
Leo Chen 5 years ago committed by GitHub
parent 1bf4836580
commit 543ff333cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -466,6 +466,17 @@ class TestVarBase(unittest.TestCase):
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):

@ -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 = [

Loading…
Cancel
Save