aboutsummaryrefslogtreecommitdiff
path: root/src/backends/reference/workloads/Gather.cpp
blob: c848a7c138995f116826ceab0ee0e0c37729ced8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "Gather.hpp"

#include "RefWorkloadUtils.hpp"

#include <backendsCommon/WorkloadData.hpp>

#include <boost/numeric/conversion/cast.hpp>

namespace armnn
{

void Gather(const TensorInfo& paramsInfo,
            const TensorInfo& indicesInfo,
            const TensorInfo& outputInfo,
            Decoder<float>& params,
            const int32_t* indices,
            Encoder<float>& output)
{
    const TensorShape& paramsShape = paramsInfo.GetShape();

    unsigned int paramsProduct = 1;
    for (unsigned int i = 1; i < paramsInfo.GetNumDimensions(); ++i)
    {
        paramsProduct = paramsProduct * paramsShape[i];
    }

    unsigned int outIndex = 0;
    for (unsigned int i = 0; i < indicesInfo.GetNumElements(); ++i)
    {
        unsigned int indx = boost::numeric_cast<unsigned int>(indices[i]);

        BOOST_ASSERT(indices[i] >= 0 && indx < paramsShape[0]);

        unsigned int startOffset = indx * paramsProduct;
        unsigned int endOffset = startOffset + paramsProduct;

        for (unsigned int j = startOffset; j < endOffset; ++j)
        {
            params[j];
            float outputValue = params.Get();
            output[outIndex];
            output.Set(outputValue);
            ++outIndex;
        }
    }

    BOOST_ASSERT(outIndex == outputInfo.GetNumElements());
}

} //namespace armnn