未验证 提交 ae6ad23c 编写于 作者: L Leo Chen 提交者: GitHub

Refine tensor to_string (#27925)

* refine to_string

* re-enable ut
上级 8b307042
...@@ -336,11 +336,6 @@ list(REMOVE_ITEM TEST_OPS test_conv3d_transpose_op) ...@@ -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_imperative_data_loader_exception)
list(REMOVE_ITEM TEST_OPS test_sampling_id_op) list(REMOVE_ITEM TEST_OPS test_sampling_id_op)
list(REMOVE_ITEM TEST_OPS test_parallel_executor_fetch_isolated_var) 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) if (APPLE OR WIN32)
list(REMOVE_ITEM TEST_OPS test_dataset) list(REMOVE_ITEM TEST_OPS test_dataset)
...@@ -606,4 +601,3 @@ if(NOT WIN32 AND NOT APPLE) ...@@ -606,4 +601,3 @@ if(NOT WIN32 AND NOT APPLE)
set_tests_properties(test_pool3d_op PROPERTIES TIMEOUT 150) set_tests_properties(test_pool3d_op PROPERTIES TIMEOUT 150)
set_tests_properties(test_regularizer PROPERTIES TIMEOUT 150) set_tests_properties(test_regularizer PROPERTIES TIMEOUT 150)
endif() endif()
...@@ -136,7 +136,7 @@ def _format_item(np_var, max_width=0): ...@@ -136,7 +136,7 @@ def _format_item(np_var, max_width=0):
def _get_max_width(var): def _get_max_width(var):
max_width = 0 max_width = 0
for item in np.nditer(var.numpy()): for item in list(var.numpy().flatten()):
item_str = _format_item(item) item_str = _format_item(item)
max_width = max(max_width, len(item_str)) max_width = max(max_width, len(item_str))
return max_width return max_width
...@@ -147,7 +147,9 @@ def _format_tensor(var, sumary, indent=0): ...@@ -147,7 +147,9 @@ def _format_tensor(var, sumary, indent=0):
max_width = _get_max_width(_to_sumary(var)) max_width = _get_max_width(_to_sumary(var))
if len(var.shape) == 0: 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: elif len(var.shape) == 1:
if sumary and var.shape[0] > 2 * edgeitems: if sumary and var.shape[0] > 2 * edgeitems:
items = [ items = [
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册