narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "Gather.hpp" |
| 7 | |
| 8 | #include "RefWorkloadUtils.hpp" |
| 9 | |
| 10 | #include <backendsCommon/WorkloadData.hpp> |
| 11 | |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 12 | #include <boost/numeric/conversion/cast.hpp> |
| 13 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 17 | void Gather(const TensorInfo& paramsInfo, |
| 18 | const TensorInfo& indicesInfo, |
| 19 | const TensorInfo& outputInfo, |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 20 | Decoder<float>& params, |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 21 | const int32_t* indices, |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 22 | Encoder<float>& output) |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 23 | { |
| 24 | const TensorShape& paramsShape = paramsInfo.GetShape(); |
| 25 | |
| 26 | unsigned int paramsProduct = 1; |
| 27 | for (unsigned int i = 1; i < paramsInfo.GetNumDimensions(); ++i) |
| 28 | { |
| 29 | paramsProduct = paramsProduct * paramsShape[i]; |
| 30 | } |
| 31 | |
| 32 | unsigned int outIndex = 0; |
| 33 | for (unsigned int i = 0; i < indicesInfo.GetNumElements(); ++i) |
| 34 | { |
| 35 | unsigned int indx = boost::numeric_cast<unsigned int>(indices[i]); |
| 36 | |
| 37 | BOOST_ASSERT(indices[i] >= 0 && indx < paramsShape[0]); |
| 38 | |
| 39 | unsigned int startOffset = indx * paramsProduct; |
| 40 | unsigned int endOffset = startOffset + paramsProduct; |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 41 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 42 | for (unsigned int j = startOffset; j < endOffset; ++j) |
| 43 | { |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 44 | params[j]; |
| 45 | float outputValue = params.Get(); |
| 46 | output[outIndex]; |
| 47 | output.Set(outputValue); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 48 | ++outIndex; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | BOOST_ASSERT(outIndex == outputInfo.GetNumElements()); |
| 53 | } |
| 54 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 55 | } //namespace armnn |