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> |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 11 | #include <armnn/utility/IgnoreUnused.hpp> |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 12 | |
Aron Virginas-Tar | d4f0fea | 2019-04-09 14:08:06 +0100 | [diff] [blame] | 13 | #include <boost/numeric/conversion/cast.hpp> |
| 14 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 15 | namespace armnn |
| 16 | { |
| 17 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 18 | void Gather(const TensorInfo& paramsInfo, |
| 19 | const TensorInfo& indicesInfo, |
| 20 | const TensorInfo& outputInfo, |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 21 | Decoder<float>& params, |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 22 | const int32_t* indices, |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 23 | Encoder<float>& output) |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 24 | { |
Jan Eilers | 8eb2560 | 2020-03-09 12:13:48 +0000 | [diff] [blame] | 25 | IgnoreUnused(outputInfo); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 26 | const TensorShape& paramsShape = paramsInfo.GetShape(); |
| 27 | |
| 28 | unsigned int paramsProduct = 1; |
| 29 | for (unsigned int i = 1; i < paramsInfo.GetNumDimensions(); ++i) |
| 30 | { |
| 31 | paramsProduct = paramsProduct * paramsShape[i]; |
| 32 | } |
| 33 | |
| 34 | unsigned int outIndex = 0; |
| 35 | for (unsigned int i = 0; i < indicesInfo.GetNumElements(); ++i) |
| 36 | { |
| 37 | unsigned int indx = boost::numeric_cast<unsigned int>(indices[i]); |
| 38 | |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 39 | ARMNN_ASSERT(indices[i] >= 0 && indx < paramsShape[0]); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 40 | |
| 41 | unsigned int startOffset = indx * paramsProduct; |
| 42 | unsigned int endOffset = startOffset + paramsProduct; |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 43 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 44 | for (unsigned int j = startOffset; j < endOffset; ++j) |
| 45 | { |
Ellen Norris-Thompson | 6858d3f | 2019-06-21 15:50:00 +0100 | [diff] [blame] | 46 | params[j]; |
| 47 | float outputValue = params.Get(); |
| 48 | output[outIndex]; |
| 49 | output.Set(outputValue); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 50 | ++outIndex; |
| 51 | } |
| 52 | } |
| 53 | |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 54 | ARMNN_ASSERT(outIndex == outputInfo.GetNumElements()); |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 55 | } |
| 56 | |
narpra01 | 4951d84 | 2019-01-18 16:53:53 +0000 | [diff] [blame] | 57 | } //namespace armnn |