ArmNN  NotReleased
ParserHelperTest.cpp File Reference
#include "../ParserHelper.hpp"
#include <armnn/Tensor.hpp>
#include <armnn/Types.hpp>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (CalculateReducedOutputTensoInfoTest)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

BOOST_AUTO_TEST_CASE ( CalculateReducedOutputTensoInfoTest  )

Definition at line 19 of file ParserHelperTest.cpp.

References BOOST_AUTO_TEST_SUITE_END(), armnnUtils::CalculateReducedOutputTensoInfo(), armnn::Float32, TensorInfo::GetNumDimensions(), and TensorInfo::GetShape().

20 {
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)
27  std::set<unsigned int> axisData1 = { 0, 1, 2 };
28  TensorInfo outputTensorInfo1;
29 
30  CalculateReducedOutputTensoInfo(inputTensorInfo, axisData1, keepDims, outputTensorInfo1);
31 
32  BOOST_ASSERT(outputTensorInfo1.GetNumDimensions() == 1);
33  BOOST_ASSERT(outputTensorInfo1.GetShape()[0] == 1);
34 
35  // Reducing dimension 0 results in a 3x4 size tensor (one dimension)
36  std::set<unsigned int> axisData2 = { 0 };
37  TensorInfo outputTensorInfo2;
38 
39  CalculateReducedOutputTensoInfo(inputTensorInfo, axisData2, keepDims, outputTensorInfo2);
40 
41  BOOST_ASSERT(outputTensorInfo2.GetNumDimensions() == 1);
42  BOOST_ASSERT(outputTensorInfo2.GetShape()[0] == 12);
43 
44  // Reducing dimensions 0,1 results in a 4 size tensor (one dimension)
45  std::set<unsigned int> axisData3 = { 0, 1 };
46  TensorInfo outputTensorInfo3;
47 
48  CalculateReducedOutputTensoInfo(inputTensorInfo, axisData3, keepDims, outputTensorInfo3);
49 
50  BOOST_ASSERT(outputTensorInfo3.GetNumDimensions() == 1);
51  BOOST_ASSERT(outputTensorInfo3.GetShape()[0] == 4);
52 
53  // Reducing dimension 0 results in a { 1, 3, 4 } dimension tensor
54  keepDims = true;
55  std::set<unsigned int> axisData4 = { 0 };
56 
57  TensorInfo outputTensorInfo4;
58 
59  CalculateReducedOutputTensoInfo(inputTensorInfo, axisData4, keepDims, outputTensorInfo4);
60 
61  BOOST_ASSERT(outputTensorInfo4.GetNumDimensions() == 3);
62  BOOST_ASSERT(outputTensorInfo4.GetShape()[0] == 1);
63  BOOST_ASSERT(outputTensorInfo4.GetShape()[1] == 3);
64  BOOST_ASSERT(outputTensorInfo4.GetShape()[2] == 4);
65 
66  // Reducing dimension 1, 2 results in a { 2, 1, 1 } dimension tensor
67  keepDims = true;
68  std::set<unsigned int> axisData5 = { 1, 2 };
69 
70  TensorInfo outputTensorInfo5;
71 
72  CalculateReducedOutputTensoInfo(inputTensorInfo, axisData5, keepDims, outputTensorInfo5);
73 
74  BOOST_ASSERT(outputTensorInfo5.GetNumDimensions() == 3);
75  BOOST_ASSERT(outputTensorInfo5.GetShape()[0] == 2);
76  BOOST_ASSERT(outputTensorInfo5.GetShape()[1] == 1);
77  BOOST_ASSERT(outputTensorInfo5.GetShape()[2] == 1);
78 
79 }
unsigned int GetNumDimensions() const
Definition: Tensor.hpp:92
void CalculateReducedOutputTensoInfo(const armnn::TensorInfo &inputTensorInfo, const std::set< unsigned int > &axisSet, bool keepDims, armnn::TensorInfo &outputTensorInfo)
Creates a tensor info after reducing the dimensions mentioned in axisData.
const TensorShape & GetShape() const
Definition: Tensor.hpp:88