blob: 6df259fa4d7c22562e1c71b1619bd3c65f053df1 [file] [log] [blame]
Matteo Martincighab9e5252019-06-13 17:27:46 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "PreluImpl.hpp"
7#include "RefWorkloadUtils.hpp"
8#include "Broadcast.hpp"
9
10namespace armnn
11{
12
Finn Williams01097942021-04-26 12:06:34 +010013void PreluImpl(const TensorInfo& inputInfo,
14 const TensorInfo& alphaInfo,
15 const TensorInfo& outputInfo,
Matteo Martincighab9e5252019-06-13 17:27:46 +010016 Decoder<float>& inputData,
17 Decoder<float>& alphaData,
18 Encoder<float>& outputData)
19{
Matteo Martincighab9e5252019-06-13 17:27:46 +010020 const TensorShape& inputShape = inputInfo.GetShape();
21 const TensorShape& alphaShape = alphaInfo.GetShape();
22 const TensorShape& outputShape = outputInfo.GetShape();
23
24 // PReLU activation: f(x) = alpha * x for x < 0, f(x) = x for x >= 0
25 auto prelu = [](float x, float alpha)
26 {
27 return x < 0 ? alpha * x : x;
28 };
29
30 BroadcastLoop(inputShape, alphaShape, outputShape).Unroll(prelu, 0, inputData, alphaData, outputData);
31}
32
33} // namespace armnn