blob: a1a49d70d7a75c02b9f8833e53feac22e38161c0 [file] [log] [blame]
Aron Virginas-Tarf03fcf02019-07-09 17:44:24 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "OutputShapeUtils.hpp"
7
8#include <algorithm>
Sadik Armagan310d8ff2019-07-11 10:53:38 +01009#include <vector>
Aron Virginas-Tarf03fcf02019-07-09 17:44:24 +010010
11namespace armnn_driver
12{
13
14using namespace armnn;
15
Aron Virginas-Tar366e0a62019-07-10 13:01:41 +010016bool IsDynamicOutput(const TensorInfo& outputInfo)
17{
18 return outputInfo.GetNumElements() == 0u;
19}
20
Sadik Armagan310d8ff2019-07-11 10:53:38 +010021TensorShape InferPadOutputShape(const TensorShape& inputShape,
22 const std::vector<std::pair<unsigned int, unsigned int>>& padList)
23{
24 const unsigned int numDims = inputShape.GetNumDimensions();
25
26 std::vector<unsigned int> outputDims;
27 TensorShape outputShape = TensorShape(numDims);
28 for (unsigned int dim = 0; dim < numDims; ++dim)
29 {
30 unsigned int dimSize = inputShape[dim];
31 const std::pair<unsigned int, unsigned int>& dimPadding = padList[dim];
32 dimSize += dimPadding.first;
33 dimSize += dimPadding.second;
34 outputShape[dim] = dimSize;
35 }
36 return outputShape;
37}
38
Aron Virginas-Tarf03fcf02019-07-09 17:44:24 +010039TensorShape InferPreluOutputShape(const TensorShape& inputShape, const TensorShape& alphaShape)
40{
41 // NOTE: The inferred PReLU output size will be the maximum size along each dimension
42 // of input and alpha, starting with the trailing dimensions, and working its way forward.
43 //
44 // Example: inputShape={4, 1, 2}, alphaShape={5, 4, 3, 1} => outputShape={5, 4, 3, 2}
45
46 const unsigned int numInputDims = inputShape.GetNumDimensions();
47 const unsigned int numAlphaDims = alphaShape.GetNumDimensions();
48
49 const unsigned int maxNumDims = std::max(numInputDims, numAlphaDims);
50
51 TensorShape outputShape = TensorShape(maxNumDims);
52 for (unsigned int reverseIdx = 1u; reverseIdx <= maxNumDims; ++reverseIdx)
53 {
54 const int inputIdx = numInputDims - reverseIdx;
55 const int alphaIdx = numAlphaDims - reverseIdx;
56
57 const unsigned int inputDimSize = inputIdx >= 0 ? inputShape[inputIdx] : 0u;
58 const unsigned int alphaDimSize = alphaIdx >= 0 ? alphaShape[alphaIdx] : 0u;
59
60 const unsigned int outputIdx = maxNumDims - reverseIdx;
61 outputShape[outputIdx] = std::max(inputDimSize, alphaDimSize);
62 }
63
64 return outputShape;
65}
66
67} // namespace armnn_driver