From afb2cb7c9caaf73268c4d59f639bc7d52002977b Mon Sep 17 00:00:00 2001 From: yongqiangma Date: Mon, 13 Apr 2020 08:32:54 -0500 Subject: [PATCH] lod_tensor_to_array error message enhance. (#23615) * lod_tensor_to_array error message enhance. test=develop --- python/paddle/fluid/layers/control_flow.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/python/paddle/fluid/layers/control_flow.py b/python/paddle/fluid/layers/control_flow.py index e80447b53c6..1b84bfc469f 100755 --- a/python/paddle/fluid/layers/control_flow.py +++ b/python/paddle/fluid/layers/control_flow.py @@ -1169,6 +1169,16 @@ def lod_tensor_to_array(x, table): table = fluid.layers.lod_rank_table(x, level=0) array = fluid.layers.lod_tensor_to_array(x, table) """ + check_type(x, 'x', (Variable, list), 'lod_tensor_to_array') + if isinstance(x, (list)): + for i, input_x in enumerate(x): + check_type(input_x, 'input[' + str(i) + ']', Variable, + 'lod_tensor_to_array') + check_type(table, 'table', (Variable, list), 'lod_tensor_to_array') + if isinstance(table, (list)): + for i, table_x in enumerate(table): + check_type(table_x, 'table[' + str(i) + ']', Variable, + 'lod_tensor_to_array') helper = LayerHelper("lod_tensor_to_array", **locals()) array = helper.create_variable( name=unique_name.generate("lod_tensor_to_array"), @@ -1204,6 +1214,17 @@ def array_to_lod_tensor(x, table): array = fluid.layers.lod_tensor_to_array(x, table) lod_tensor = fluid.layers.array_to_lod_tensor(array, table) """ + check_type(x, 'x', (Variable, list), 'array_to_lod_tensor') + if isinstance(x, (list)): + for i, input_x in enumerate(x): + check_type(input_x, 'input[' + str(i) + ']', Variable, + 'array_to_lod_tensor') + check_type(table, 'table', (Variable, list), 'array_to_lod_tensor') + if isinstance(table, (list)): + for i, table_x in enumerate(table): + check_type(table_x, 'table[' + str(i) + ']', Variable, + 'array_to_lod_tensor') + helper = LayerHelper("array_to_lod_tensor", **locals()) tmp = helper.create_variable_for_type_inference(dtype=x.dtype) helper.append_op( -- GitLab