[Topk_v2 Op] introduce topk_v2 test cases (#1304)
author최성진/동작제어Lab(SR)/Principal Engineer/삼성전자 <lotieye.choi@samsung.com>
Thu, 24 May 2018 00:51:19 +0000 (09:51 +0900)
committer오형석/동작제어Lab(SR)/Senior Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 24 May 2018 00:51:19 +0000 (09:51 +0900)
* [Topk_v2 Op] introduce topk_v2 test cases

This commit introduces topk_v2 test cases.
-1D float
-2D float

Signed-off-by: SungJin Choi <lotieye.choi@samsung.com>
* [Topk_v2 Op] add new line at the end of line

This commit adds new lines at the end of line

Signed-off-by: SungJin Choi <lotieye.choi@samsung.com>
runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp
runtimes/tests/neural_networks_test/generated/examples/topk_v2_1D_float.example.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/generated/examples/topk_v2_2D_float.example.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/generated/models/topk_v2_1D_float.model.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/generated/models/topk_v2_2D_float.model.cpp [new file with mode: 0644]
runtimes/tests/neural_networks_test/specs/Ex/topk_v2_1D_float.mod.py [new file with mode: 0644]
runtimes/tests/neural_networks_test/specs/Ex/topk_v2_2D_float.mod.py [new file with mode: 0644]

index 33717ca..0cb502b 100644 (file)
@@ -2268,3 +2268,31 @@ TEST_F(GeneratedTests, cast_ex_int32_to_float32) {
             cast_ex_int32_to_float32::is_ignored,
             cast_ex_int32_to_float32::examples);
 }
+
+namespace topk_v2_1D_float {
+std::vector<MixedTypedExample> examples = {
+// Generated topk_v2_1D_float test
+#include "generated/examples/topk_v2_1D_float.example.cpp"
+};
+// Generated model constructor
+#include "generated/models/topk_v2_1D_float.model.cpp"
+} // namespace topk_v2_1D_float
+TEST_F(GeneratedTests, topk_v2_1D_float) {
+    execute(topk_v2_1D_float::CreateModel,
+            topk_v2_1D_float::is_ignored,
+            topk_v2_1D_float::examples);
+}
+
+namespace topk_v2_2D_float {
+std::vector<MixedTypedExample> examples = {
+// Generated topk_v2_2D_float test
+#include "generated/examples/topk_v2_2D_float.example.cpp"
+};
+// Generated model constructor
+#include "generated/models/topk_v2_2D_float.model.cpp"
+} // namespace topk_v2_2D_float
+TEST_F(GeneratedTests, topk_v2_2D_float) {
+    execute(topk_v2_2D_float::CreateModel,
+            topk_v2_2D_float::is_ignored,
+            topk_v2_2D_float::examples);
+}
diff --git a/runtimes/tests/neural_networks_test/generated/examples/topk_v2_1D_float.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/topk_v2_1D_float.example.cpp
new file mode 100644 (file)
index 0000000..88521f9
--- /dev/null
@@ -0,0 +1,22 @@
+// Generated file (from: topk_v2_1D_float.mod.py). Do not edit
+// Begin of an example
+{
+//Input(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {{0, {3.123456789123457f, 4.123456789123456f, 5.123456789123456f, 6.123456789123456f}}},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {}
+},
+//Output(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {{1, {6.123456789123456f, 5.123456789123456f}}},
+  // int -> INT32 map
+  {{0, {3, 2}}},
+  // int -> QUANT8_ASYMM map
+  {}
+}
+}, // End of an example
diff --git a/runtimes/tests/neural_networks_test/generated/examples/topk_v2_2D_float.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/topk_v2_2D_float.example.cpp
new file mode 100644 (file)
index 0000000..2962f77
--- /dev/null
@@ -0,0 +1,22 @@
+// Generated file (from: topk_v2_2D_float.mod.py). Do not edit
+// Begin of an example
+{
+//Input(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {{0, {3.123456789123457f, 4.123456789123456f, 5.123456789123456f, 6.123456789123456f, 7.123456789123456f, 8.123456789123457f, 9.123456789123457f, 1.1234567891234568f, 2.123456789123457f, 18.123456789123455f, 19.123456789123455f, 11.123456789123457f}}},
+  // int -> INT32 map
+  {},
+  // int -> QUANT8_ASYMM map
+  {}
+},
+//Output(s)
+{ // See tools/test_generator/include/TestHarness.h:MixedTyped
+  // int -> FLOAT32 map
+  {{1, {6.123456789123456f, 5.123456789123456f, 9.123456789123457f, 8.123456789123457f, 19.123456789123455f, 18.123456789123455f}}},
+  // int -> INT32 map
+  {{0, {3, 2, 2, 1, 2, 1}}},
+  // int -> QUANT8_ASYMM map
+  {}
+}
+}, // End of an example
diff --git a/runtimes/tests/neural_networks_test/generated/models/topk_v2_1D_float.model.cpp b/runtimes/tests/neural_networks_test/generated/models/topk_v2_1D_float.model.cpp
new file mode 100644 (file)
index 0000000..40d225b
--- /dev/null
@@ -0,0 +1,26 @@
+// Generated file (from: topk_v2_1D_float.mod.py). Do not edit
+void CreateModel(Model *model) {
+  OperandType type1(Type::INT32, {});
+  OperandType type3(Type::TENSOR_FLOAT32, {2});
+  OperandType type0(Type::TENSOR_FLOAT32, {4});
+  OperandType type2(Type::TENSOR_INT32, {2});
+  // Phase 1, operands
+  auto op1 = model->addOperand(&type0);
+  auto k = model->addOperand(&type1);
+  auto op2 = model->addOperand(&type2);
+  auto op3 = model->addOperand(&type3);
+  // Phase 2, operations
+  static int32_t k_init[] = {2};
+  model->setOperandValue(k, k_init, sizeof(int32_t) * 1);
+  model->addOperationEx(ANEURALNETWORKS_TOPK_V2_EX, {op1, k}, {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/topk_v2_2D_float.model.cpp b/runtimes/tests/neural_networks_test/generated/models/topk_v2_2D_float.model.cpp
new file mode 100644 (file)
index 0000000..a94f6e1
--- /dev/null
@@ -0,0 +1,26 @@
+// Generated file (from: topk_v2_2D_float.mod.py). Do not edit
+void CreateModel(Model *model) {
+  OperandType type1(Type::INT32, {});
+  OperandType type3(Type::TENSOR_FLOAT32, {3,2});
+  OperandType type0(Type::TENSOR_FLOAT32, {3,4});
+  OperandType type2(Type::TENSOR_INT32, {3,2});
+  // Phase 1, operands
+  auto op1 = model->addOperand(&type0);
+  auto k = model->addOperand(&type1);
+  auto op2 = model->addOperand(&type2);
+  auto op3 = model->addOperand(&type3);
+  // Phase 2, operations
+  static int32_t k_init[] = {2};
+  model->setOperandValue(k, k_init, sizeof(int32_t) * 1);
+  model->addOperationEx(ANEURALNETWORKS_TOPK_V2_EX, {op1, k}, {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/topk_v2_1D_float.mod.py b/runtimes/tests/neural_networks_test/specs/Ex/topk_v2_1D_float.mod.py
new file mode 100644 (file)
index 0000000..d0dca61
--- /dev/null
@@ -0,0 +1,19 @@
+# model
+model = Model()
+i1 = Input("op1", "TENSOR_FLOAT32", "{4}") # a vector of input
+k = Int32Scalar("k", 2)
+i2 = Output("op2", "TENSOR_INT32", "{2}") # indexes of output
+i3 = Output("op3", "TENSOR_FLOAT32", "{2}") # values of output
+model = model.Operation("TOPK_V2_EX", i1, k).To([i2, i3])
+
+# Example 1. Input in operand 0,
+input0 = {i1: # input 0
+          [3.123456789123456789, 4.123456789123456789, 5.123456789123456789, 6.123456789123456789]}
+
+output0 = {i2: # output 0
+           [3, 2],
+           i3: # output 1
+           [6.123456789123456789, 5.123456789123456789]}
+
+# Instantiate an example
+Example((input0, output0))
diff --git a/runtimes/tests/neural_networks_test/specs/Ex/topk_v2_2D_float.mod.py b/runtimes/tests/neural_networks_test/specs/Ex/topk_v2_2D_float.mod.py
new file mode 100644 (file)
index 0000000..7de691c
--- /dev/null
@@ -0,0 +1,25 @@
+# model
+model = Model()
+i1 = Input("op1", "TENSOR_FLOAT32", "{3,4}") # a matirx of input
+k = Int32Scalar("k", 2)
+o1 = Output("op2", "TENSOR_INT32", "{3,2}") # indexes of output
+o2 = Output("op3", "TENSOR_FLOAT32", "{3,2}") # values of output
+model = model.Operation("TOPK_V2_EX", i1, k).To([o1, o2])
+
+# Example 1. Input in operand 0,
+input0 = {i1: # input 0
+          [3.123456789123456789, 4.123456789123456789, 5.123456789123456789, 6.123456789123456789,
+          7.123456789123456789, 8.123456789123456789, 9.123456789123456789, 1.123456789123456789,
+          2.123456789123456789, 18.123456789123456789, 19.123456789123456789, 11.123456789123456789]}
+
+output0 = {o1: # output 0
+           [3, 2,
+           2, 1,
+           2, 1],
+           o2: # output 1
+           [6.123456789123456789, 5.123456789123456789, 
+           9.123456789123456789, 8.123456789123456789,
+           19.123456789123456789, 18.123456789123456789]}
+
+# Instantiate an example
+Example((input0, output0))