From 82dced96e626d1ad6ce9f248be48d38208101a5b Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9D=B4=ED=95=9C=EC=A2=85/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Engineer/=EC=82=BC=EC=84=B1=EC=A0=84?= =?utf8?q?=EC=9E=90?= Date: Tue, 11 Sep 2018 15:23:10 +0900 Subject: [PATCH] [neurun] Add assert condition to insertOperation (#2639) The node to be added in `Graph::insertOperation` must not have any inputs. Signed-off-by: Hanjoung Lee --- runtimes/neurun/src/graph/Graph.cc | 1 + runtimes/neurun/test/graph/operation/Insert.cc | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/runtimes/neurun/src/graph/Graph.cc b/runtimes/neurun/src/graph/Graph.cc index 06116ec..19bc26b 100644 --- a/runtimes/neurun/src/graph/Graph.cc +++ b/runtimes/neurun/src/graph/Graph.cc @@ -65,6 +65,7 @@ operation::Index Graph::insertOperation(const operand::Index &prev_operand_index auto next_input_indexes = next_operation.getInputs(); assert(next_input_indexes.contains(prev_operand_index)); + assert(node->getInputs().size() == 0); // node to be inserted must not have any inputs node->setInputs({prev_operand_index}); diff --git a/runtimes/neurun/test/graph/operation/Insert.cc b/runtimes/neurun/test/graph/operation/Insert.cc index 6f3f53f..c938ab4 100644 --- a/runtimes/neurun/test/graph/operation/Insert.cc +++ b/runtimes/neurun/test/graph/operation/Insert.cc @@ -61,17 +61,17 @@ TEST(graph_operation_manipulation, operation_insertion) // Insert node1 (between 1 and 2) auto inserted_operand1 = graph.addOperand(shape, type); - auto inserted_index1 = graph.insertOperation( - operand1, mocknode_index2, - nnfw::make_unique(IndexSet{operand1}, IndexSet{inserted_operand1})); + auto inserted_index1 = + graph.insertOperation(operand1, mocknode_index2, + nnfw::make_unique(IndexSet{}, IndexSet{inserted_operand1})); ASSERT_EQ(inserted_index1.asInt(), 3); // Insert node2 (between 2 and 3) auto inserted_operand2 = graph.addOperand(shape, type); - auto inserted_index2 = graph.insertOperation( - operand2, mocknode_index3, - nnfw::make_unique(IndexSet{operand2}, IndexSet{inserted_operand2})); + auto inserted_index2 = + graph.insertOperation(operand2, mocknode_index3, + nnfw::make_unique(IndexSet{}, IndexSet{inserted_operand2})); ASSERT_EQ(inserted_index2.asInt(), 4); @@ -121,17 +121,17 @@ TEST(graph_operation_manipulation, operation_insertion_multi_input) // Insert node1 (between 1 and multi) auto inserted_operand1 = graph.addOperand(shape, type); - auto inserted_index1 = graph.insertOperation( - operand1, multiinput_index, - nnfw::make_unique(IndexSet{operand1}, IndexSet{inserted_operand1})); + auto inserted_index1 = + graph.insertOperation(operand1, multiinput_index, + nnfw::make_unique(IndexSet{}, IndexSet{inserted_operand1})); ASSERT_EQ(inserted_index1.asInt(), 3); // Insert node2 (between 2 and multi) auto inserted_operand2 = graph.addOperand(shape, type); - auto inserted_index2 = graph.insertOperation( - operand2, multiinput_index, - nnfw::make_unique(IndexSet{operand2}, IndexSet{inserted_operand2})); + auto inserted_index2 = + graph.insertOperation(operand2, multiinput_index, + nnfw::make_unique(IndexSet{}, IndexSet{inserted_operand2})); ASSERT_EQ(inserted_index2.asInt(), 4); -- 2.7.4