From a578f81370c6e041f1a412abbb7fe6b37f40dbae Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=B5=9C=EC=84=B1=EC=A7=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Principal=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Thu, 24 May 2018 11:35:47 +0900 Subject: [PATCH] [Gather Op] add Gather-2D operation test (#1296) This commit introduces a test for Gather-2D operation. Signed-off-by: SungJin Choi --- .../generated/all_generated_tests.cpp | 32 ++++++---------------- .../generated/examples/gather_2D_float.example.cpp | 22 +++++++++++++++ .../generated/models/gather_2D_float.model.cpp | 22 +++++++++++++++ .../specs/Ex/gather_2D_float.mod.py | 21 ++++++++++++++ 4 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 runtimes/tests/neural_networks_test/generated/examples/gather_2D_float.example.cpp create mode 100644 runtimes/tests/neural_networks_test/generated/models/gather_2D_float.model.cpp create mode 100644 runtimes/tests/neural_networks_test/specs/Ex/gather_2D_float.mod.py diff --git a/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp b/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp index 0cb502b..8197ccc 100644 --- a/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp +++ b/runtimes/tests/neural_networks_test/generated/all_generated_tests.cpp @@ -2241,32 +2241,18 @@ TEST_F(GeneratedTests, sub) { sub::examples); } -namespace cast_ex_float32_to_int32 { +namespace gather_2D_float { std::vector examples = { -// Generated cast_ex_float32_to_int32 test -#include "generated/examples/cast_ex_float32_to_int32.example.cpp" +// Generated gather_2D_float test +#include "generated/examples/gather_2D_float.example.cpp" }; // Generated model constructor -#include "generated/models/cast_ex_float32_to_int32.model.cpp" -} // namespace cast_ex_float32_to_int32 -TEST_F(GeneratedTests, cast_ex_float32_to_int32) { - execute(cast_ex_float32_to_int32::CreateModel, - cast_ex_float32_to_int32::is_ignored, - cast_ex_float32_to_int32::examples); -} - -namespace cast_ex_int32_to_float32 { -std::vector examples = { -// Generated cast_ex_int32_to_float32 test -#include "generated/examples/cast_ex_int32_to_float32.example.cpp" -}; -// Generated model constructor -#include "generated/models/cast_ex_int32_to_float32.model.cpp" -} // namespace cast_ex_int32_to_float32 -TEST_F(GeneratedTests, cast_ex_int32_to_float32) { - execute(cast_ex_int32_to_float32::CreateModel, - cast_ex_int32_to_float32::is_ignored, - cast_ex_int32_to_float32::examples); +#include "generated/models/gather_2D_float.model.cpp" +} // namespace gather_2D_float +TEST_F(GeneratedTests, gather_2D_float) { + execute(gather_2D_float::CreateModel, + gather_2D_float::is_ignored, + gather_2D_float::examples); } namespace topk_v2_1D_float { diff --git a/runtimes/tests/neural_networks_test/generated/examples/gather_2D_float.example.cpp b/runtimes/tests/neural_networks_test/generated/examples/gather_2D_float.example.cpp new file mode 100644 index 0000000..0bf46fd --- /dev/null +++ b/runtimes/tests/neural_networks_test/generated/examples/gather_2D_float.example.cpp @@ -0,0 +1,22 @@ +// Generated file (from: gather_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 + {{1, {2, 0}}}, + // int -> QUANT8_ASYMM map + {} +}, +//Output(s) +{ // See tools/test_generator/include/TestHarness.h:MixedTyped + // int -> FLOAT32 map + {{0, {2.123456789123457f, 18.123456789123455f, 19.123456789123455f, 11.123456789123457f, 3.123456789123457f, 4.123456789123456f, 5.123456789123456f, 6.123456789123456f}}}, + // int -> INT32 map + {}, + // int -> QUANT8_ASYMM map + {} +} +}, // End of an example diff --git a/runtimes/tests/neural_networks_test/generated/models/gather_2D_float.model.cpp b/runtimes/tests/neural_networks_test/generated/models/gather_2D_float.model.cpp new file mode 100644 index 0000000..81270d7 --- /dev/null +++ b/runtimes/tests/neural_networks_test/generated/models/gather_2D_float.model.cpp @@ -0,0 +1,22 @@ +// Generated file (from: gather_2D_float.mod.py). Do not edit +void CreateModel(Model *model) { + OperandType type2(Type::TENSOR_FLOAT32, {2,4}); + OperandType type0(Type::TENSOR_FLOAT32, {3,4}); + OperandType type1(Type::TENSOR_INT32, {2}); + // Phase 1, operands + auto op1 = model->addOperand(&type0); + auto op2 = model->addOperand(&type1); + auto op3 = model->addOperand(&type2); + // Phase 2, operations + model->addOperationEx(ANEURALNETWORKS_GATHER_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 ignore = {}; + return ignore.find(i) != ignore.end(); +} diff --git a/runtimes/tests/neural_networks_test/specs/Ex/gather_2D_float.mod.py b/runtimes/tests/neural_networks_test/specs/Ex/gather_2D_float.mod.py new file mode 100644 index 0000000..82fbf57 --- /dev/null +++ b/runtimes/tests/neural_networks_test/specs/Ex/gather_2D_float.mod.py @@ -0,0 +1,21 @@ +# model +model = Model() +i1 = Input("op1", "TENSOR_FLOAT32", "{3,4}") # a vector of 2 float32s +i2 = Input("op2", "TENSOR_INT32", "{2}") # another vector of 2 int32s +i3 = Output("op3", "TENSOR_FLOAT32", "{2,4}") +model = model.Operation("GATHER_EX", i1, i2).To(i3) + +# 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], + i2: # input 1 + [2, 0]} + +output0 = {i3: # output 0 + [2.123456789123456789, 18.123456789123456789, 19.123456789123456789, 11.123456789123456789, + 3.123456789123456789, 4.123456789123456789, 5.123456789123456789, 6.123456789123456789]} + +# Instantiate an example +Example((input0, output0)) -- 2.7.4