2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include <boost/test/unit_test.hpp>
7 #include "ParserFlatbuffersSerializeFixture.hpp"
8 #include "../Deserializer.hpp"
13 BOOST_AUTO_TEST_SUITE(Deserializer)
15 struct L2NormalizationFixture : public ParserFlatbuffersSerializeFixture
17 explicit L2NormalizationFixture(const std::string &inputShape,
18 const std::string &outputShape,
19 const std::string &dataType,
20 const std::string &dataLayout,
21 const std::string epsilon)
29 layer_type: "InputLayer",
35 layerName: "InputLayer",
39 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
44 dimensions: )" + inputShape + R"(,
45 dataType: ")" + dataType + R"(",
46 quantizationScale: 0.5,
55 layer_type: "L2NormalizationLayer",
59 layerName: "L2NormalizationLayer",
60 layerType: "L2Normalization",
63 connection: {sourceLayerIndex:0, outputSlotIndex:0 },
68 dimensions: )" + outputShape + R"(,
69 dataType: ")" + dataType + R"("
74 dataLayout: ")" + dataLayout + R"(",
75 eps: )" + epsilon + R"(
80 layer_type: "OutputLayer",
86 layerName: "OutputLayer",
90 connection: {sourceLayerIndex:1, outputSlotIndex:0 },
95 dimensions: )" + outputShape + R"(,
96 dataType: ")" + dataType + R"("
108 struct L2NormFixture : L2NormalizationFixture
110 // Using a non standard epsilon value of 1e-8
111 L2NormFixture():L2NormalizationFixture("[ 1, 3, 1, 1 ]",
118 BOOST_FIXTURE_TEST_CASE(L2NormalizationFloat32, L2NormFixture)
120 // 1 / sqrt(1^2 + 2^2 + 3^2)
121 const float approxInvL2Norm = 0.267261f;
123 RunTest<4, armnn::DataType::Float32>(0,
124 {{"InputLayer", { 1.0f, 2.0f, 3.0f }}},
125 {{"OutputLayer",{ 1.0f * approxInvL2Norm,
126 2.0f * approxInvL2Norm,
127 3.0f * approxInvL2Norm }}});
130 BOOST_FIXTURE_TEST_CASE(L2NormalizationEpsilonLimitFloat32, L2NormFixture)
133 const float approxInvL2Norm = 10000;
135 RunTest<4, armnn::DataType::Float32>(0,
136 {{"InputLayer", { 0.00000001f, 0.00000002f, 0.00000003f }}},
137 {{"OutputLayer",{ 0.00000001f * approxInvL2Norm,
138 0.00000002f * approxInvL2Norm,
139 0.00000003f * approxInvL2Norm }}});
142 BOOST_AUTO_TEST_SUITE_END()