[neurun] Add assert condition to insertOperation (#2639)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Tue, 11 Sep 2018 06:23:10 +0000 (15:23 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Tue, 11 Sep 2018 06:23:10 +0000 (15:23 +0900)
The node to be added in `Graph::insertOperation` must not have any
inputs.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/Graph.cc
runtimes/neurun/test/graph/operation/Insert.cc

index 06116ec..19bc26b 100644 (file)
@@ -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});
 
index 6f3f53f..c938ab4 100644 (file)
@@ -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<MockNode>(IndexSet{operand1}, IndexSet{inserted_operand1}));
+  auto inserted_index1 =
+      graph.insertOperation(operand1, mocknode_index2,
+                            nnfw::make_unique<MockNode>(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<MockNode>(IndexSet{operand2}, IndexSet{inserted_operand2}));
+  auto inserted_index2 =
+      graph.insertOperation(operand2, mocknode_index3,
+                            nnfw::make_unique<MockNode>(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<MockNode>(IndexSet{operand1}, IndexSet{inserted_operand1}));
+  auto inserted_index1 =
+      graph.insertOperation(operand1, multiinput_index,
+                            nnfw::make_unique<MockNode>(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<MockNode>(IndexSet{operand2}, IndexSet{inserted_operand2}));
+  auto inserted_index2 =
+      graph.insertOperation(operand2, multiinput_index,
+                            nnfw::make_unique<MockNode>(IndexSet{}, IndexSet{inserted_operand2}));
 
   ASSERT_EQ(inserted_index2.asInt(), 4);