Aron Virginas-Tar | c949ab5 | 2019-10-14 16:43:13 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ParserFlatbuffersSerializeFixture.hpp" |
| 7 | #include "../Deserializer.hpp" |
| 8 | |
| 9 | #include <boost/test/unit_test.hpp> |
| 10 | |
| 11 | BOOST_AUTO_TEST_SUITE(Deserializer) |
| 12 | |
| 13 | struct LogSoftmaxFixture : public ParserFlatbuffersSerializeFixture |
| 14 | { |
| 15 | explicit LogSoftmaxFixture(const std::string &shape, |
| 16 | const std::string &beta, |
| 17 | const std::string &axis, |
| 18 | const std::string &dataType) |
| 19 | { |
| 20 | m_JsonString = R"( |
| 21 | { |
| 22 | inputIds: [0], |
| 23 | outputIds: [2], |
| 24 | layers: [ |
| 25 | { |
| 26 | layer_type: "InputLayer", |
| 27 | layer: { |
| 28 | base: { |
| 29 | layerBindingId: 0, |
| 30 | base: { |
| 31 | index: 0, |
| 32 | layerName: "InputLayer", |
| 33 | layerType: "Input", |
| 34 | inputSlots: [{ |
| 35 | index: 0, |
| 36 | connection: { sourceLayerIndex:0, outputSlotIndex:0 }, |
| 37 | }], |
| 38 | outputSlots: [{ |
| 39 | index: 0, |
| 40 | tensorInfo: { |
| 41 | dimensions: )" + shape + R"(, |
| 42 | dataType: ")" + dataType + R"(", |
| 43 | quantizationScale: 0.5, |
| 44 | quantizationOffset: 0 |
| 45 | }, |
| 46 | }] |
| 47 | }, |
| 48 | } |
| 49 | }, |
| 50 | }, |
| 51 | { |
| 52 | layer_type: "LogSoftmaxLayer", |
| 53 | layer : { |
| 54 | base: { |
| 55 | index:1, |
| 56 | layerName: "LogSoftmaxLayer", |
| 57 | layerType: "LogSoftmax", |
| 58 | inputSlots: [{ |
| 59 | index: 0, |
| 60 | connection: { sourceLayerIndex:0, outputSlotIndex:0 }, |
| 61 | }], |
| 62 | outputSlots: [{ |
| 63 | index: 0, |
| 64 | tensorInfo: { |
| 65 | dimensions: )" + shape + R"(, |
| 66 | dataType: ")" + dataType + R"(" |
| 67 | }, |
| 68 | }], |
| 69 | }, |
| 70 | descriptor: { |
| 71 | beta: ")" + beta + R"(", |
| 72 | axis: )" + axis + R"( |
| 73 | }, |
| 74 | }, |
| 75 | }, |
| 76 | { |
| 77 | layer_type: "OutputLayer", |
| 78 | layer: { |
| 79 | base:{ |
| 80 | layerBindingId: 0, |
| 81 | base: { |
| 82 | index: 2, |
| 83 | layerName: "OutputLayer", |
| 84 | layerType: "Output", |
| 85 | inputSlots: [{ |
| 86 | index: 0, |
| 87 | connection: { sourceLayerIndex:1, outputSlotIndex:0 }, |
| 88 | }], |
| 89 | outputSlots: [ { |
| 90 | index: 0, |
| 91 | tensorInfo: { |
| 92 | dimensions: )" + shape + R"(, |
| 93 | dataType: ")" + dataType + R"(" |
| 94 | }, |
| 95 | }], |
| 96 | } |
| 97 | }}, |
| 98 | }] |
| 99 | })"; |
| 100 | SetupSingleInputSingleOutput("InputLayer", "OutputLayer"); |
| 101 | } |
| 102 | }; |
| 103 | |
| 104 | struct LogSoftmaxFloat32Fixture : LogSoftmaxFixture |
| 105 | { |
| 106 | LogSoftmaxFloat32Fixture() : |
| 107 | LogSoftmaxFixture("[ 1, 1, 2, 4 ]", // inputShape |
| 108 | "1.0", // beta |
| 109 | "3", // axis |
| 110 | "Float32") // dataType |
| 111 | {} |
| 112 | }; |
| 113 | |
| 114 | BOOST_FIXTURE_TEST_CASE(LogSoftmaxFloat32, LogSoftmaxFloat32Fixture) |
| 115 | { |
| 116 | RunTest<4, armnn::DataType::Float32>( |
| 117 | 0, |
| 118 | { |
| 119 | 0.f, -6.f, 2.f, 4.f, |
| 120 | 3.f, -2.f, 10.f, 1.f |
| 121 | }, |
| 122 | { |
| 123 | -4.14297f, -10.14297f, -2.14297f, -0.14297f, |
| 124 | -7.00104f, -12.00104f, -0.00105f, -9.00104f |
| 125 | }); |
| 126 | } |
| 127 | |
| 128 | BOOST_AUTO_TEST_SUITE_END() |