aboutsummaryrefslogtreecommitdiff
path: root/src/backends/reference/workloads/PreluImpl.cpp
blob: 6df259fa4d7c22562e1c71b1619bd3c65f053df1 (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
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "PreluImpl.hpp"
#include "RefWorkloadUtils.hpp"
#include "Broadcast.hpp"

namespace armnn
{

void PreluImpl(const TensorInfo& inputInfo,
               const TensorInfo& alphaInfo,
               const TensorInfo& outputInfo,
               Decoder<float>& inputData,
               Decoder<float>& alphaData,
               Encoder<float>& outputData)
{
    const TensorShape& inputShape  = inputInfo.GetShape();
    const TensorShape& alphaShape  = alphaInfo.GetShape();
    const TensorShape& outputShape = outputInfo.GetShape();

    // PReLU activation: f(x) = alpha * x for x < 0, f(x) = x for x >= 0
    auto prelu = [](float x, float alpha)
    {
        return x < 0 ? alpha * x : x;
    };

    BroadcastLoop(inputShape, alphaShape, outputShape).Unroll(prelu, 0, inputData, alphaData, outputData);
}

} // namespace armnn