ArmNN
 21.11
ElementWiseUnary.cpp File Reference

Go to the source code of this file.

Functions

 TEST_SUITE ("TensorflowLiteParser_ElementwiseUnary")
 

Function Documentation

◆ TEST_SUITE()

TEST_SUITE ( "TensorflowLiteParser_ElementwiseUnary"  )

Definition at line 9 of file ElementWiseUnary.cpp.

References ParserFlatbuffersFixture::Setup(), and TEST_CASE_FIXTURE().

10 {
11 struct ElementWiseUnaryFixture : public ParserFlatbuffersFixture
12 {
13  explicit ElementWiseUnaryFixture(const std::string& operatorCode,
14  const std::string& dataType,
15  const std::string& inputShape,
16  const std::string& outputShape)
17  {
18  m_JsonString = R"(
19  {
20  "version": 3,
21  "operator_codes": [ { "builtin_code": )" + operatorCode + R"( } ],
22  "subgraphs": [ {
23  "tensors": [
24  {
25  "shape": )" + inputShape + R"(,
26  "type": )" + dataType + R"( ,
27  "buffer": 0,
28  "name": "inputTensor",
29  "quantization": {
30  "min": [ 0.0 ],
31  "max": [ 255.0 ],
32  "scale": [ 1.0 ],
33  "zero_point": [ 0 ],
34  }
35  },
36  {
37  "shape": )" + outputShape + R"( ,
38  "type": )" + dataType + R"( ,
39  "buffer": 1,
40  "name": "outputTensor",
41  "quantization": {
42  "min": [ 0.0 ],
43  "max": [ 255.0 ],
44  "scale": [ 1.0 ],
45  "zero_point": [ 0 ],
46  }
47  }
48  ],
49  "inputs": [ 0 ],
50  "outputs": [ 1 ],
51  "operators": [
52  {
53  "opcode_index": 0,
54  "inputs": [ 0 ],
55  "outputs": [ 1 ],
56  "custom_options_format": "FLEXBUFFERS"
57  }
58  ],
59  } ],
60  "buffers" : [
61  { },
62  { }
63  ]
64  }
65  )";
66  Setup();
67  }
68 };
69 
70 struct SimpleAbsFixture : public ElementWiseUnaryFixture
71 {
72  SimpleAbsFixture() : ElementWiseUnaryFixture("ABS", "FLOAT32", "[ 2, 2 ]", "[ 2, 2 ]") {}
73 };
74 
75 TEST_CASE_FIXTURE(SimpleAbsFixture, "ParseAbs")
76 {
77  std::vector<float> inputValues
78  {
79  -0.1f, 0.2f,
80  0.3f, -0.4f
81  };
82 
83  // Calculate output data
84  std::vector<float> expectedOutputValues(inputValues.size());
85  for (unsigned int i = 0; i < inputValues.size(); ++i)
86  {
87  expectedOutputValues[i] = std::abs(inputValues[i]);
88  }
89 
90  RunTest<2, armnn::DataType::Float32>(0, {{ "inputTensor", { inputValues } }},
91  {{ "outputTensor",{ expectedOutputValues } } });
92 }
93 
94 struct SimpleExpFixture : public ElementWiseUnaryFixture
95 {
96  SimpleExpFixture() : ElementWiseUnaryFixture("EXP", "FLOAT32", "[ 1, 2, 3, 1 ]", "[ 1, 2, 3, 1 ]") {}
97 };
98 
99 TEST_CASE_FIXTURE(SimpleExpFixture, "ParseExp")
100 {
101  RunTest<4, armnn::DataType::Float32>(0, {{ "inputTensor", { 0.0f, 1.0f, 2.0f,
102  3.0f, 4.0f, 5.0f} }},
103  {{ "outputTensor",{ 1.0f, 2.718281f, 7.3890515f,
104  20.0855185f, 54.5980834f, 148.4129329f} } });
105 }
106 
107 struct SimpleLogicalNotFixture : public ElementWiseUnaryFixture
108 {
109  SimpleLogicalNotFixture() : ElementWiseUnaryFixture("LOGICAL_NOT", "BOOL", "[ 1, 1, 1, 4 ]", "[ 1, 1, 1, 4 ]") {}
110 };
111 
112 TEST_CASE_FIXTURE(SimpleLogicalNotFixture, "ParseLogicalNot")
113 {
114  RunTest<4, armnn::DataType::Boolean>(0, {{ "inputTensor", { 0, 1, 0, 1 } }},
115  {{ "outputTensor",{ 1, 0, 1, 0 } } });
116 }
117 
118 struct SimpleNegFixture : public ElementWiseUnaryFixture
119 {
120  SimpleNegFixture() : ElementWiseUnaryFixture("NEG", "FLOAT32", "[ 1, 2, 3, 1 ]", "[ 1, 2, 3, 1 ]") {}
121 };
122 
123 TEST_CASE_FIXTURE(SimpleNegFixture, "ParseNeg")
124 {
125  RunTest<4, armnn::DataType::Float32>(0, {{ "inputTensor", { 0.0f, 1.0f, -2.0f,
126  20.0855185f, -54.5980834f, 5.0f} }},
127  {{ "outputTensor",{ 0.0f, -1.0f, 2.0f,
128  -20.0855185f, 54.5980834f, -5.0f} }});
129 }
130 
131 struct SimpleRsqrtFixture : public ElementWiseUnaryFixture
132 {
133  SimpleRsqrtFixture() : ElementWiseUnaryFixture("RSQRT", "FLOAT32", "[ 1, 2, 3, 1 ]", "[ 1, 2, 3, 1 ]") {}
134 };
135 
136 TEST_CASE_FIXTURE(SimpleRsqrtFixture, "ParseRsqrt")
137 {
138  RunTest<4, armnn::DataType::Float32>(0, {{ "inputTensor", { 1.0f, 4.0f, 16.0f,
139  25.0f, 64.0f, 100.0f } }},
140  {{ "outputTensor",{ 1.0f, 0.5f, 0.25f,
141  0.2f, 0.125f, 0.1f} }});
142 }
143 
144 }
TEST_CASE_FIXTURE(ClContextControlFixture, "CopyBetweenNeonAndGpu")
void Setup(bool testDynamic=true)