6 #include <boost/test/unit_test.hpp> 8 #include "../TfLiteParser.hpp" 17 explicit L2NormalizationFixture(
const std::string & inputOutputShape)
22 "operator_codes": [ { "builtin_code": "L2_NORMALIZATION" } ], 26 "shape": )" + inputOutputShape + R"(, 29 "name": "inputTensor", 38 "shape": )" + inputOutputShape + R"(, 41 "name": "outputTensor", 57 "custom_options_format": "FLEXBUFFERS" 72 const float reduction = std::accumulate(elements.begin(), elements.end(), 0.0f,
73 [](
float acc,
float element) {
return acc + element * element; });
74 const float eps = 1e-12f;
75 const float max = reduction < eps ? eps : reduction;
79 struct L2NormalizationFixture4D : L2NormalizationFixture
82 L2NormalizationFixture4D() : L2NormalizationFixture(
"[ 1, 1, 4, 3 ]") {}
87 RunTest<4, armnn::DataType::Float32>(
89 {{
"inputTensor", { 1.0f, 2.0f, 3.0f,
92 10.0f, 11.0f, 12.0f }}},
94 {{
"outputTensor", { 1.0f /
CalcL2Norm({ 1.0f, 2.0f, 3.0f }),
108 12.0f /
CalcL2Norm({ 10.0f, 11.0f, 12.0f }) }}});
111 struct L2NormalizationSimpleFixture4D : L2NormalizationFixture
113 L2NormalizationSimpleFixture4D() : L2NormalizationFixture(
"[ 1, 1, 1, 4 ]") {}
118 RunTest<4, armnn::DataType::Float32>(
120 {{
"inputTensor", { 0.00000001f, 0.00000002f, 0.00000003f, 0.00000004f }}},
122 {{
"outputTensor", { 0.00000001f /
CalcL2Norm({ 0.00000001f, 0.00000002f, 0.00000003f, 0.00000004f }),
123 0.00000002f /
CalcL2Norm({ 0.00000001f, 0.00000002f, 0.00000003f, 0.00000004f }),
124 0.00000003f /
CalcL2Norm({ 0.00000001f, 0.00000002f, 0.00000003f, 0.00000004f }),
125 0.00000004f /
CalcL2Norm({ 0.00000001f, 0.00000002f, 0.00000003f, 0.00000004f }) }}});
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
BOOST_FIXTURE_TEST_CASE(ParseL2Normalization4D, L2NormalizationFixture4D)
float CalcL2Norm(std::initializer_list< float > elements)
BOOST_AUTO_TEST_SUITE_END()