blob: c848a7c138995f116826ceab0ee0e0c37729ced8 [file] [log] [blame]
narpra014951d842019-01-18 16:53:53 +00001//
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-Tard4f0fea2019-04-09 14:08:06 +010012#include <boost/numeric/conversion/cast.hpp>
13
narpra014951d842019-01-18 16:53:53 +000014namespace armnn
15{
16
narpra014951d842019-01-18 16:53:53 +000017void Gather(const TensorInfo& paramsInfo,
18 const TensorInfo& indicesInfo,
19 const TensorInfo& outputInfo,
Ellen Norris-Thompson6858d3f2019-06-21 15:50:00 +010020 Decoder<float>& params,
narpra014951d842019-01-18 16:53:53 +000021 const int32_t* indices,
Ellen Norris-Thompson6858d3f2019-06-21 15:50:00 +010022 Encoder<float>& output)
narpra014951d842019-01-18 16:53:53 +000023{
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-Thompson6858d3f2019-06-21 15:50:00 +010041
narpra014951d842019-01-18 16:53:53 +000042 for (unsigned int j = startOffset; j < endOffset; ++j)
43 {
Ellen Norris-Thompson6858d3f2019-06-21 15:50:00 +010044 params[j];
45 float outputValue = params.Get();
46 output[outIndex];
47 output.Set(outputValue);
narpra014951d842019-01-18 16:53:53 +000048 ++outIndex;
49 }
50 }
51
52 BOOST_ASSERT(outIndex == outputInfo.GetNumElements());
53}
54
narpra014951d842019-01-18 16:53:53 +000055} //namespace armnn