From ae6ad23c3c79d77d8b0a456ed17539c32130d08b Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 14 Oct 2020 17:22:08 +0800 Subject: [PATCH] Refine tensor to_string (#27925) * refine to_string * re-enable ut --- python/paddle/fluid/tests/unittests/CMakeLists.txt | 6 ------ python/paddle/tensor/to_string.py | 6 ++++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/CMakeLists.txt b/python/paddle/fluid/tests/unittests/CMakeLists.txt index 60f9247f00..8f1b963ac8 100644 --- a/python/paddle/fluid/tests/unittests/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/CMakeLists.txt @@ -336,11 +336,6 @@ list(REMOVE_ITEM TEST_OPS test_conv3d_transpose_op) list(REMOVE_ITEM TEST_OPS test_imperative_data_loader_exception) list(REMOVE_ITEM TEST_OPS test_sampling_id_op) list(REMOVE_ITEM TEST_OPS test_parallel_executor_fetch_isolated_var) -if (APPLE) - list(REMOVE_ITEM TEST_OPS test_imperative_framework) - list(REMOVE_ITEM TEST_OPS test_learning_rate_scheduler) - list(REMOVE_ITEM TEST_OPS test_var_base) -endif() if (APPLE OR WIN32) list(REMOVE_ITEM TEST_OPS test_dataset) @@ -606,4 +601,3 @@ if(NOT WIN32 AND NOT APPLE) set_tests_properties(test_pool3d_op PROPERTIES TIMEOUT 150) set_tests_properties(test_regularizer PROPERTIES TIMEOUT 150) endif() - diff --git a/python/paddle/tensor/to_string.py b/python/paddle/tensor/to_string.py index 940ad92048..0da110146a 100644 --- a/python/paddle/tensor/to_string.py +++ b/python/paddle/tensor/to_string.py @@ -136,7 +136,7 @@ def _format_item(np_var, max_width=0): def _get_max_width(var): max_width = 0 - for item in np.nditer(var.numpy()): + for item in list(var.numpy().flatten()): item_str = _format_item(item) max_width = max(max_width, len(item_str)) return max_width @@ -147,7 +147,9 @@ def _format_tensor(var, sumary, indent=0): max_width = _get_max_width(_to_sumary(var)) if len(var.shape) == 0: - return _format_item(var.numpy.items(0), max_width) + # currently, shape = [], i.e., scaler tensor is not supported. + # If it is supported, it should be formatted like this. + return _format_item(var.numpy().item(0), max_width) elif len(var.shape) == 1: if sumary and var.shape[0] > 2 * edgeitems: items = [ -- GitLab