Add GTest for testing the enabled Broadcast of EqualEx op (#3304)
authorPrasanna R/System SW /SRI-Bangalore/Engineer/삼성전자 <prasanna.r@samsung.com>
Fri, 16 Nov 2018 07:21:13 +0000 (12:51 +0530)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Fri, 16 Nov 2018 07:21:13 +0000 (16:21 +0900)
This patch adds GTest for testing the enabled Broadcast of EqualEx op.
Added GTests:
```
equal_ex_broadcast
equal_ex_broadcast_4D_2D
```
Signed-off-by: prasannar <prasanna.r@samsung.com>
runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp
runtimes/tests/neural_networks_test/generated/examples/equal_ex_broadcast.example.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/generated/examples/equal_ex_broadcast_4D_2D.example.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/generated/models/equal_ex_broadcast.model.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/generated/models/equal_ex_broadcast_4D_2D.model.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/specs/Ex/equal_ex_broadcast.mod.py [new file with mode: 0644]
runtimes/tests/neural_networks_test/specs/Ex/equal_ex_broadcast_4D_2D.mod.py [new file with mode: 0644]

index dde93ed..5f02028 100644 (file)
@@ -3067,6 +3067,34 @@ TEST_F(GeneratedTests, equal_ex_4D_float) {
             equal_ex_4D_float::examples);
 }
 
+namespace equal_ex_broadcast_4D_2D {
+std::vector<MixedTypedExample> examples = {
+// Generated equal_ex_broadcast_4D_2D test
+#include "generated/examples/equal_ex_broadcast_4D_2D.example.cpp"
+};
+// Generated model constructor
+#include "generated/models/equal_ex_broadcast_4D_2D.model.cpp"
+} // namespace equal_ex_broadcast_4D_2D
+TEST_F(GeneratedTests, equal_ex_broadcast_4D_2D) {
+    execute(equal_ex_broadcast_4D_2D::CreateModel,
+            equal_ex_broadcast_4D_2D::is_ignored,
+            equal_ex_broadcast_4D_2D::examples);
+}
+
+namespace equal_ex_broadcast {
+std::vector<MixedTypedExample> examples = {
+// Generated equal_ex_broadcast test
+#include "generated/examples/equal_ex_broadcast.example.cpp"
+};
+// Generated model constructor
+#include "generated/models/equal_ex_broadcast.model.cpp"
+} // namespace equal_ex_broadcast
+TEST_F(GeneratedTests, equal_ex_broadcast) {
+    execute(equal_ex_broadcast::CreateModel,
+            equal_ex_broadcast::is_ignored,
+            equal_ex_broadcast::examples);
+}
+
 namespace equal_ex_quant8 {
 std::vector<MixedTypedExample> examples = {
 // Generated equal_ex_quant8 test
diff --git a/runtimes/tests/neural_networks_test/generated/examples/equal_ex_broadcast.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/equal_ex_broadcast.example.cpp
new file mode 100644 (file)
index 0000000..efffa81
--- /dev/null
@@ -0,0 +1,22 @@
+// Generated file (from: equal_ex_broadcast.mod.py). Do not edit
+// Begin of an example
+{
+//Input(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {{0, {123, 321, 2, 7}}, {1, {0, 7}}},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {}
+},
+//Output(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {{0, {0, 0, 0, 1}}}
+}
+}, // End of an example
diff --git a/runtimes/tests/neural_networks_test/generated/examples/equal_ex_broadcast_4D_2D.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/equal_ex_broadcast_4D_2D.example.cpp
new file mode 100644 (file)
index 0000000..157eb68
--- /dev/null
@@ -0,0 +1,22 @@
+// Generated file (from: equal_ex_broadcast_4D_2D.mod.py). Do not edit
+// Begin of an example
+{
+//Input(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {{0, {4, 11, 9, 10, 8, 2, 1, 0, 3, 1, 8, 6, 11, 3, 8, 1, 0, 3, 2, 7, 4, 9, 11, 3}}, {1, {8, 3, 2, 10}}},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {}
+},
+//Output(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {{0, {0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}}}
+}
+}, // End of an example
diff --git a/runtimes/tests/neural_networks_test/generated/models/equal_ex_broadcast.model.cpp b/runtimes/tests/neural_networks_test/generated/models/equal_ex_broadcast.model.cpp
new file mode 100644 (file)
index 0000000..0d12e61
--- /dev/null
@@ -0,0 +1,22 @@
+// Generated file (from: equal_ex_broadcast.mod.py). Do not edit
+void CreateModel(Model *model) {
+  OperandType type1(Type::TENSOR_FLOAT32, {1, 2});
+  OperandType type0(Type::TENSOR_FLOAT32, {2, 2});
+  OperandType type2(Type::TENSOR_QUANT8_ASYMM, {2, 2}, 1.f, 0);
+  // Phase 1, operands
+  auto op1 = model->addOperand(&type0);
+  auto op2 = model->addOperand(&type1);
+  auto op3 = model->addOperand(&type2);
+  // Phase 2, operations
+  model->addOperationEx(ANEURALNETWORKS_EQUAL_EX, {op1, op2}, {op3});
+  // Phase 3, inputs and outputs
+  model->identifyInputsAndOutputs(
+    {op1, op2},
+    {op3});
+  assert(model->isValid());
+}
+
+bool is_ignored(int i) {
+  static std::set<int> ignore = {};
+  return ignore.find(i) != ignore.end();
+}
diff --git a/runtimes/tests/neural_networks_test/generated/models/equal_ex_broadcast_4D_2D.model.cpp b/runtimes/tests/neural_networks_test/generated/models/equal_ex_broadcast_4D_2D.model.cpp
new file mode 100644 (file)
index 0000000..da03114
--- /dev/null
@@ -0,0 +1,22 @@
+// Generated file (from: equal_ex_broadcast_4D_2D.mod.py). Do not edit
+void CreateModel(Model *model) {
+  OperandType type1(Type::TENSOR_FLOAT32, {2, 2});
+  OperandType type0(Type::TENSOR_FLOAT32, {3, 2, 2, 2});
+  OperandType type2(Type::TENSOR_QUANT8_ASYMM, {3, 2, 2, 2}, 1.f, 0);
+  // Phase 1, operands
+  auto op1 = model->addOperand(&type0);
+  auto op2 = model->addOperand(&type1);
+  auto op3 = model->addOperand(&type2);
+  // Phase 2, operations
+  model->addOperationEx(ANEURALNETWORKS_EQUAL_EX, {op1, op2}, {op3});
+  // Phase 3, inputs and outputs
+  model->identifyInputsAndOutputs(
+    {op1, op2},
+    {op3});
+  assert(model->isValid());
+}
+
+bool is_ignored(int i) {
+  static std::set<int> ignore = {};
+  return ignore.find(i) != ignore.end();
+}
diff --git a/runtimes/tests/neural_networks_test/specs/Ex/equal_ex_broadcast.mod.py b/runtimes/tests/neural_networks_test/specs/Ex/equal_ex_broadcast.mod.py
new file mode 100644 (file)
index 0000000..65da6b9
--- /dev/null
@@ -0,0 +1,19 @@
+# model
+model = Model()
+i1 = Input("op1", "TENSOR_FLOAT32", "{2, 2}")
+i2 = Input("op2", "TENSOR_FLOAT32", "{1, 2}")
+
+i3 = Output("op3", "TENSOR_QUANT8_ASYMM", "{2, 2}, 1.f, 0")
+model = model.Operation("EQUAL_EX", i1, i2).To(i3)
+
+# Example 1. Input in operand 0,
+input0 = {i1: # input 0
+          [123, 321, 2, 7],
+          i2: # input 1
+          [0, 7]}
+
+output0 = {i3: # output 0
+           [0, 0, 0, 1]}
+
+# Instantiate an example
+Example((input0, output0))
diff --git a/runtimes/tests/neural_networks_test/specs/Ex/equal_ex_broadcast_4D_2D.mod.py b/runtimes/tests/neural_networks_test/specs/Ex/equal_ex_broadcast_4D_2D.mod.py
new file mode 100644 (file)
index 0000000..3a3599e
--- /dev/null
@@ -0,0 +1,30 @@
+# model
+model = Model()
+i1 = Input("op1", "TENSOR_FLOAT32", "{3, 2, 2, 2}")
+i2 = Input("op2", "TENSOR_FLOAT32", "{2, 2}")
+
+i3 = Output("op3", "TENSOR_QUANT8_ASYMM", "{3, 2, 2, 2}, 1.f, 0")
+model = model.Operation("EQUAL_EX", i1, i2).To(i3)
+
+# Example 1. Input in operand 0,
+input0 = {i1: # input 0
+          [4, 11, 9, 10,
+           8, 2, 1, 0,
+           3, 1, 8, 6,
+           11, 3, 8, 1,
+           0, 3, 2, 7,
+           4, 9, 11, 3],
+          i2: # input 1
+          [8, 3, 2, 10]}
+
+output0 = {i3: # output 0
+           [0, 0, 0, 1,
+            1, 0, 0, 0,
+            0, 0, 0, 0,
+            0, 1, 0, 0,
+            0, 1, 1, 0,
+            0, 0, 0, 0]
+          }
+
+# Instantiate an example
+Example((input0, output0))