aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/backends/RefWorkloads/Division.cpp
blob: 9837fea6b43df344783a85ea17ee89012e5b0311 (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
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// See LICENSE file in the project root for full license information.
//

#include "Division.hpp"
#include "Broadcast.hpp"

#include <functional>

namespace
{

void ElementwiseDivision(unsigned int numElements,
                         const float* inData0,
                         const float* inData1,
                         float* outData)
{
    for (unsigned int i = 0; i < numElements; ++i)
    {
        //TODO How to handle divide by 0
        outData[i] = inData0[i] / inData1[i];
    }
}

} // namespace

namespace armnn
{

void Division(const TensorShape& inShape0,
              const TensorShape& inShape1,
              const TensorShape& outShape,
              const float* inData0,
              const float* inData1,
              float* outData)
{
    if (inShape0 == inShape1)
    {
        ElementwiseDivision(inShape0.GetNumElements(), inData0, inData1, outData);
    }
    else
    {
        BroadcastLoop(inShape0, inShape1, outShape).Unroll(std::divides<float>(),
                                                           0,
                                                           inData0,
                                                           inData1,
                                                           outData);
    }
}

} //namespace armnn