blob: 2ed9bd1f03db78eb2fe444d956e1f7614fc942f9 [file] [log] [blame]
Ferran Balaguer51dd62f2019-01-11 19:29:18 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "../ParserHelper.hpp"
7
Matthew Benthamff130e22020-01-17 11:47:42 +00008#include <armnn/Tensor.hpp>
9#include <armnn/Types.hpp>
10
Sadik Armagan1625efc2021-06-10 18:24:34 +010011#include <doctest/doctest.h>
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000012
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000013
14using namespace armnn;
15using namespace armnnUtils;
16
Sadik Armagan1625efc2021-06-10 18:24:34 +010017TEST_SUITE("ParserHelperSuite")
18{
19TEST_CASE("CalculateReducedOutputTensoInfoTest")
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000020{
21 bool keepDims = false;
22
23 unsigned int inputShape[] = { 2, 3, 4 };
24 TensorInfo inputTensorInfo(3, &inputShape[0], DataType::Float32);
25
26 // Reducing all dimensions results in one single output value (one dimension)
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000027 std::set<unsigned int> axisData1 = { 0, 1, 2 };
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000028 TensorInfo outputTensorInfo1;
29
Derek Lambertibaa177f2019-12-10 22:00:43 +000030 CalculateReducedOutputTensoInfo(inputTensorInfo, axisData1, keepDims, outputTensorInfo1);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000031
Sadik Armagan1625efc2021-06-10 18:24:34 +010032 CHECK(outputTensorInfo1.GetNumDimensions() == 1);
33 CHECK(outputTensorInfo1.GetShape()[0] == 1);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000034
35 // Reducing dimension 0 results in a 3x4 size tensor (one dimension)
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000036 std::set<unsigned int> axisData2 = { 0 };
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000037 TensorInfo outputTensorInfo2;
38
Derek Lambertibaa177f2019-12-10 22:00:43 +000039 CalculateReducedOutputTensoInfo(inputTensorInfo, axisData2, keepDims, outputTensorInfo2);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000040
Sadik Armagan1625efc2021-06-10 18:24:34 +010041 CHECK(outputTensorInfo2.GetNumDimensions() == 1);
42 CHECK(outputTensorInfo2.GetShape()[0] == 12);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000043
44 // Reducing dimensions 0,1 results in a 4 size tensor (one dimension)
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000045 std::set<unsigned int> axisData3 = { 0, 1 };
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000046 TensorInfo outputTensorInfo3;
47
Derek Lambertibaa177f2019-12-10 22:00:43 +000048 CalculateReducedOutputTensoInfo(inputTensorInfo, axisData3, keepDims, outputTensorInfo3);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000049
Sadik Armagan1625efc2021-06-10 18:24:34 +010050 CHECK(outputTensorInfo3.GetNumDimensions() == 1);
51 CHECK(outputTensorInfo3.GetShape()[0] == 4);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000052
53 // Reducing dimension 0 results in a { 1, 3, 4 } dimension tensor
54 keepDims = true;
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000055 std::set<unsigned int> axisData4 = { 0 };
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000056
57 TensorInfo outputTensorInfo4;
58
Derek Lambertibaa177f2019-12-10 22:00:43 +000059 CalculateReducedOutputTensoInfo(inputTensorInfo, axisData4, keepDims, outputTensorInfo4);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000060
Sadik Armagan1625efc2021-06-10 18:24:34 +010061 CHECK(outputTensorInfo4.GetNumDimensions() == 3);
62 CHECK(outputTensorInfo4.GetShape()[0] == 1);
63 CHECK(outputTensorInfo4.GetShape()[1] == 3);
64 CHECK(outputTensorInfo4.GetShape()[2] == 4);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000065
66 // Reducing dimension 1, 2 results in a { 2, 1, 1 } dimension tensor
67 keepDims = true;
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000068 std::set<unsigned int> axisData5 = { 1, 2 };
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000069
70 TensorInfo outputTensorInfo5;
71
Derek Lambertibaa177f2019-12-10 22:00:43 +000072 CalculateReducedOutputTensoInfo(inputTensorInfo, axisData5, keepDims, outputTensorInfo5);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000073
Sadik Armagan1625efc2021-06-10 18:24:34 +010074 CHECK(outputTensorInfo5.GetNumDimensions() == 3);
75 CHECK(outputTensorInfo5.GetShape()[0] == 2);
76 CHECK(outputTensorInfo5.GetShape()[1] == 1);
77 CHECK(outputTensorInfo5.GetShape()[2] == 1);
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000078
79}
80
Sadik Armagan1625efc2021-06-10 18:24:34 +010081}
Ferran Balaguer51dd62f2019-01-11 19:29:18 +000082