blob: afae188bd60e4fe237d41bed6f9ac6746258395e [file] [log] [blame]
David Beck591cdb72018-09-11 16:37:14 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Éanna Ó Catháind57415d2018-11-28 16:24:38 +00006#include "ElementwiseFunction.hpp"
David Beck591cdb72018-09-11 16:37:14 +01007#include "Broadcast.hpp"
8#include <functional>
Éanna Ó Catháin20e58802018-12-04 10:29:06 +00009#include "Minimum.hpp"
saoste012df12b32018-11-28 16:57:20 +000010#include "Maximum.hpp"
josh minor4a3c6102020-01-06 16:40:46 -060011#include "Abs.hpp"
12#include "Exp.hpp"
13#include "Rsqrt.hpp"
14#include "Sqrt.hpp"
15
saoste012df12b32018-11-28 16:57:20 +000016
David Beck591cdb72018-09-11 16:37:14 +010017namespace armnn
18{
19
Derek Lambertif30f7d32019-04-09 10:25:02 +010020template <typename Functor>
josh minor4a3c6102020-01-06 16:40:46 -060021ElementwiseBinaryFunction<Functor>::ElementwiseBinaryFunction(const TensorShape& inShape0,
22 const TensorShape& inShape1,
23 const TensorShape& outShape,
24 Decoder<InType>& inData0,
25 Decoder<InType>& inData1,
26 Encoder<OutType>& outData)
David Beck591cdb72018-09-11 16:37:14 +010027{
28 BroadcastLoop(inShape0, inShape1, outShape).Unroll(Functor(), 0, inData0, inData1, outData);
29}
30
josh minor4a3c6102020-01-06 16:40:46 -060031template <typename Functor>
32ElementwiseUnaryFunction<Functor>::ElementwiseUnaryFunction(const TensorShape& inShape,
33 const TensorShape& outShape,
34 Decoder<InType>& inData,
35 Encoder<OutType>& outData)
36{
37 BroadcastLoop(inShape, outShape).Unroll(Functor(), 0, inData, outData);
38}
39
David Beck591cdb72018-09-11 16:37:14 +010040} //namespace armnn
41
josh minor4a3c6102020-01-06 16:40:46 -060042template struct armnn::ElementwiseBinaryFunction<std::plus<float>>;
43template struct armnn::ElementwiseBinaryFunction<std::minus<float>>;
44template struct armnn::ElementwiseBinaryFunction<std::multiplies<float>>;
45template struct armnn::ElementwiseBinaryFunction<std::divides<float>>;
46template struct armnn::ElementwiseBinaryFunction<armnn::maximum<float>>;
47template struct armnn::ElementwiseBinaryFunction<armnn::minimum<float>>;
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +010048
Finn Williamscbd2c232020-06-22 15:58:32 +010049template struct armnn::ElementwiseBinaryFunction<std::plus<int32_t>>;
50template struct armnn::ElementwiseBinaryFunction<std::minus<int32_t>>;
51template struct armnn::ElementwiseBinaryFunction<std::multiplies<int32_t>>;
52template struct armnn::ElementwiseBinaryFunction<std::divides<int32_t>>;
53template struct armnn::ElementwiseBinaryFunction<armnn::maximum<int32_t>>;
54template struct armnn::ElementwiseBinaryFunction<armnn::minimum<int32_t>>;
55
Aron Virginas-Tar77bfb5e2019-10-16 17:45:38 +010056// Comparison
josh minor4a3c6102020-01-06 16:40:46 -060057template struct armnn::ElementwiseBinaryFunction<std::equal_to<float>>;
58template struct armnn::ElementwiseBinaryFunction<std::greater<float>>;
59template struct armnn::ElementwiseBinaryFunction<std::greater_equal<float>>;
60template struct armnn::ElementwiseBinaryFunction<std::less<float>>;
61template struct armnn::ElementwiseBinaryFunction<std::less_equal<float>>;
62template struct armnn::ElementwiseBinaryFunction<std::not_equal_to<float>>;
63
64// Unary
65template struct armnn::ElementwiseUnaryFunction<armnn::abs<float>>;
66template struct armnn::ElementwiseUnaryFunction<armnn::exp<float>>;
67template struct armnn::ElementwiseUnaryFunction<std::negate<float>>;
68template struct armnn::ElementwiseUnaryFunction<armnn::rsqrt<float>>;
69template struct armnn::ElementwiseUnaryFunction<armnn::sqrt<float>>;