2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
8 #include "RefWorkloadUtils.hpp"
10 #include <backendsCommon/WorkloadData.hpp>
12 #include <boost/core/ignore_unused.hpp>
13 #include <boost/numeric/conversion/cast.hpp>
18 void Gather(const TensorInfo& paramsInfo,
19 const TensorInfo& indicesInfo,
20 const TensorInfo& outputInfo,
21 Decoder<float>& params,
22 const int32_t* indices,
23 Encoder<float>& output)
25 boost::ignore_unused(outputInfo);
26 const TensorShape& paramsShape = paramsInfo.GetShape();
28 unsigned int paramsProduct = 1;
29 for (unsigned int i = 1; i < paramsInfo.GetNumDimensions(); ++i)
31 paramsProduct = paramsProduct * paramsShape[i];
34 unsigned int outIndex = 0;
35 for (unsigned int i = 0; i < indicesInfo.GetNumElements(); ++i)
37 unsigned int indx = boost::numeric_cast<unsigned int>(indices[i]);
39 BOOST_ASSERT(indices[i] >= 0 && indx < paramsShape[0]);
41 unsigned int startOffset = indx * paramsProduct;
42 unsigned int endOffset = startOffset + paramsProduct;
44 for (unsigned int j = startOffset; j < endOffset; ++j)
47 float outputValue = params.Get();
49 output.Set(outputValue);
54 BOOST_ASSERT(outIndex == outputInfo.GetNumElements());