Ferran Balaguer | 51dd62f | 2019-01-11 19:29:18 +0000 | [diff] [blame^] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "../ParserHelper.hpp" |
| 7 | |
| 8 | #include <boost/test/unit_test.hpp> |
| 9 | |
| 10 | #include "armnn/Types.hpp" |
| 11 | |
| 12 | using namespace armnn; |
| 13 | using namespace armnnUtils; |
| 14 | |
| 15 | BOOST_AUTO_TEST_SUITE(ParserHelperSuite) |
| 16 | |
| 17 | BOOST_AUTO_TEST_CASE(CalculateReducedOutputTensoInfoTest) |
| 18 | { |
| 19 | bool keepDims = false; |
| 20 | |
| 21 | unsigned int inputShape[] = { 2, 3, 4 }; |
| 22 | TensorInfo inputTensorInfo(3, &inputShape[0], DataType::Float32); |
| 23 | |
| 24 | // Reducing all dimensions results in one single output value (one dimension) |
| 25 | unsigned int axisShape1[] = { 3 }; |
| 26 | std::set<unsigned int> axisData1 = { 0, 1, 2 }; |
| 27 | TensorInfo axisTensorInfo1(1, &axisShape1[0], DataType::Signed32); |
| 28 | |
| 29 | TensorInfo outputTensorInfo1; |
| 30 | |
| 31 | CalculateReducedOutputTensoInfo(inputTensorInfo, axisTensorInfo1, axisData1, |
| 32 | keepDims, outputTensorInfo1); |
| 33 | |
| 34 | BOOST_ASSERT(outputTensorInfo1.GetNumDimensions() == 1); |
| 35 | BOOST_ASSERT(outputTensorInfo1.GetShape()[0] == 1); |
| 36 | |
| 37 | // Reducing dimension 0 results in a 3x4 size tensor (one dimension) |
| 38 | unsigned int axisShape2[] = { 1 }; |
| 39 | std::set<unsigned int> axisData2 = { 0 }; |
| 40 | TensorInfo axisTensorInfo2(1, &axisShape2[0], DataType::Signed32); |
| 41 | |
| 42 | TensorInfo outputTensorInfo2; |
| 43 | |
| 44 | CalculateReducedOutputTensoInfo(inputTensorInfo, axisTensorInfo2, axisData2, |
| 45 | keepDims, outputTensorInfo2); |
| 46 | |
| 47 | BOOST_ASSERT(outputTensorInfo2.GetNumDimensions() == 1); |
| 48 | BOOST_ASSERT(outputTensorInfo2.GetShape()[0] == 12); |
| 49 | |
| 50 | // Reducing dimensions 0,1 results in a 4 size tensor (one dimension) |
| 51 | unsigned int axisShape3[] = { 2 }; |
| 52 | std::set<unsigned int> axisData3 = { 0, 1 }; |
| 53 | TensorInfo axisTensorInfo3(1, &axisShape3[0], DataType::Signed32); |
| 54 | |
| 55 | TensorInfo outputTensorInfo3; |
| 56 | |
| 57 | CalculateReducedOutputTensoInfo(inputTensorInfo, axisTensorInfo3, axisData3, |
| 58 | keepDims, outputTensorInfo3); |
| 59 | |
| 60 | BOOST_ASSERT(outputTensorInfo3.GetNumDimensions() == 1); |
| 61 | BOOST_ASSERT(outputTensorInfo3.GetShape()[0] == 4); |
| 62 | |
| 63 | // Reducing dimension 0 results in a { 1, 3, 4 } dimension tensor |
| 64 | keepDims = true; |
| 65 | unsigned int axisShape4[] = { 1 }; |
| 66 | std::set<unsigned int> axisData4 = { 0 }; |
| 67 | TensorInfo axisTensorInfo4(1, &axisShape4[0], DataType::Signed32); |
| 68 | |
| 69 | TensorInfo outputTensorInfo4; |
| 70 | |
| 71 | CalculateReducedOutputTensoInfo(inputTensorInfo, axisTensorInfo4, axisData4, |
| 72 | keepDims, outputTensorInfo4); |
| 73 | |
| 74 | BOOST_ASSERT(outputTensorInfo4.GetNumDimensions() == 3); |
| 75 | BOOST_ASSERT(outputTensorInfo4.GetShape()[0] == 1); |
| 76 | BOOST_ASSERT(outputTensorInfo4.GetShape()[1] == 3); |
| 77 | BOOST_ASSERT(outputTensorInfo4.GetShape()[2] == 4); |
| 78 | |
| 79 | // Reducing dimension 1, 2 results in a { 2, 1, 1 } dimension tensor |
| 80 | keepDims = true; |
| 81 | unsigned int axisShape5[] = { 2 }; |
| 82 | std::set<unsigned int> axisData5 = { 1, 2 }; |
| 83 | TensorInfo axisTensorInfo5(1, &axisShape5[0], DataType::Signed32); |
| 84 | |
| 85 | TensorInfo outputTensorInfo5; |
| 86 | |
| 87 | CalculateReducedOutputTensoInfo(inputTensorInfo, axisTensorInfo5, axisData5, |
| 88 | keepDims, outputTensorInfo5); |
| 89 | |
| 90 | BOOST_ASSERT(outputTensorInfo5.GetNumDimensions() == 3); |
| 91 | BOOST_ASSERT(outputTensorInfo5.GetShape()[0] == 2); |
| 92 | BOOST_ASSERT(outputTensorInfo5.GetShape()[1] == 1); |
| 93 | BOOST_ASSERT(outputTensorInfo5.GetShape()[2] == 1); |
| 94 | |
| 95 | } |
| 96 | |
| 97 | BOOST_AUTO_TEST_SUITE_END() |
| 98 | |