xref: /aosp_15_r20/external/armnn/include/armnnUtils/TensorUtils.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2018-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/TypesUtils.hpp>
9 #include <armnn/Tensor.hpp>
10 #include <armnn/Types.hpp>
11 #include <armnnUtils/TensorUtils.hpp>
12 #include <utility>
13 #include <vector>
14 
15 namespace armnn
16 {
17 class ITensorHandle;
18 }  // namespace armnn
19 
20 namespace armnnUtils
21 {
22 armnn::TensorShape GetTensorShape(unsigned int numberOfBatches,
23                                   unsigned int numberOfChannels,
24                                   unsigned int height,
25                                   unsigned int width,
26                                   const armnn::DataLayout dataLayout);
27 
28 armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches,
29                                 unsigned int numberOfChannels,
30                                 unsigned int height,
31                                 unsigned int width,
32                                 const armnn::DataLayout dataLayout,
33                                 const armnn::DataType dataType);
34 
35 armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches,
36                                 unsigned int numberOfChannels,
37                                 unsigned int depth,
38                                 unsigned int height,
39                                 unsigned int width,
40                                 const armnn::DataLayout dataLayout,
41                                 const armnn::DataType dataType);
42 
43 std::pair<float, float> FindMinMax(armnn::ITensorHandle* tensorHandle);
44 
45 armnn::TensorShape ReduceDims(const armnn::TensorShape& tensorInfo, unsigned int dimensions);
46 
47 armnn::TensorInfo ReduceDims(const armnn::TensorInfo& tensorInfo, unsigned int dimensions);
48 
49 armnn::TensorShape ExpandDims(const armnn::TensorShape& tensorShape, int axis);
50 
51 armnn::TensorShape ExpandDimsToRank(const armnn::TensorShape& tensorShape, unsigned int rank);
52 
53 std::vector<unsigned int> SqueezeDims(const armnn::TensorShape& tensorShape);
54 
55 unsigned int GetNumElementsBetween(const armnn::TensorShape& shape,
56                                    unsigned int firstAxisInclusive,
57                                    unsigned int lastAxisExclusive);
58 
59 unsigned int GetUnsignedAxis(const unsigned int inputDimension, const int axis);
60 
61 unsigned int GetNumElementsAfter(const armnn::TensorShape& shape, unsigned int axis);
62 
63 std::pair<unsigned int, std::vector<float>> GetPerAxisParams(const armnn::TensorInfo& info);
64 
65 template<typename PrimitiveType>
66 std::unique_ptr<float[]> ToFloatArray(const std::vector<PrimitiveType>& data, const armnn::TensorInfo& tensorInfo);
67 
68 std::unique_ptr<float[]> ToFloatArray(const std::vector<uint8_t>& data, const armnn::TensorInfo& tensorInfo);
69 
70 } // namespace armnnUtils
71