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> |
| 9 | |
| 10 | namespace armnn_driver |
| 11 | { |
| 12 | |
| 13 | using namespace armnn; |
| 14 | |
Aron Virginas-Tar | 366e0a6 | 2019-07-10 13:01:41 +0100 | [diff] [blame^] | 15 | bool IsDynamicOutput(const TensorInfo& outputInfo) |
| 16 | { |
| 17 | return outputInfo.GetNumElements() == 0u; |
| 18 | } |
| 19 | |
Aron Virginas-Tar | f03fcf0 | 2019-07-09 17:44:24 +0100 | [diff] [blame] | 20 | TensorShape InferPreluOutputShape(const TensorShape& inputShape, const TensorShape& alphaShape) |
| 21 | { |
| 22 | // NOTE: The inferred PReLU output size will be the maximum size along each dimension |
| 23 | // of input and alpha, starting with the trailing dimensions, and working its way forward. |
| 24 | // |
| 25 | // Example: inputShape={4, 1, 2}, alphaShape={5, 4, 3, 1} => outputShape={5, 4, 3, 2} |
| 26 | |
| 27 | const unsigned int numInputDims = inputShape.GetNumDimensions(); |
| 28 | const unsigned int numAlphaDims = alphaShape.GetNumDimensions(); |
| 29 | |
| 30 | const unsigned int maxNumDims = std::max(numInputDims, numAlphaDims); |
| 31 | |
| 32 | TensorShape outputShape = TensorShape(maxNumDims); |
| 33 | for (unsigned int reverseIdx = 1u; reverseIdx <= maxNumDims; ++reverseIdx) |
| 34 | { |
| 35 | const int inputIdx = numInputDims - reverseIdx; |
| 36 | const int alphaIdx = numAlphaDims - reverseIdx; |
| 37 | |
| 38 | const unsigned int inputDimSize = inputIdx >= 0 ? inputShape[inputIdx] : 0u; |
| 39 | const unsigned int alphaDimSize = alphaIdx >= 0 ? alphaShape[alphaIdx] : 0u; |
| 40 | |
| 41 | const unsigned int outputIdx = maxNumDims - reverseIdx; |
| 42 | outputShape[outputIdx] = std::max(inputDimSize, alphaDimSize); |
| 43 | } |
| 44 | |
| 45 | return outputShape; |
| 46 | } |
| 47 | |
| 48 | } // namespace armnn_driver |