Aron Virginas-Tar | f03fcf0 | 2019-07-09 17:44:24 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "OutputShapeUtils.hpp" |
| 7 | |
| 8 | #include <algorithm> |
Sadik Armagan | 310d8ff | 2019-07-11 10:53:38 +0100 | [diff] [blame^] | 9 | #include <vector> |
Aron Virginas-Tar | f03fcf0 | 2019-07-09 17:44:24 +0100 | [diff] [blame] | 10 | |
| 11 | namespace armnn_driver |
| 12 | { |
| 13 | |
| 14 | using namespace armnn; |
| 15 | |
Aron Virginas-Tar | 366e0a6 | 2019-07-10 13:01:41 +0100 | [diff] [blame] | 16 | bool IsDynamicOutput(const TensorInfo& outputInfo) |
| 17 | { |
| 18 | return outputInfo.GetNumElements() == 0u; |
| 19 | } |
| 20 | |
Sadik Armagan | 310d8ff | 2019-07-11 10:53:38 +0100 | [diff] [blame^] | 21 | TensorShape 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-Tar | f03fcf0 | 2019-07-09 17:44:24 +0100 | [diff] [blame] | 39 | TensorShape 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 |