blob: 5687cf5861ac4e9009d2c8e2d82aa13aff3b31ef [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
49// Comparison
josh minor4a3c6102020-01-06 16:40:46 -060050template struct armnn::ElementwiseBinaryFunction<std::equal_to<float>>;
51template struct armnn::ElementwiseBinaryFunction<std::greater<float>>;
52template struct armnn::ElementwiseBinaryFunction<std::greater_equal<float>>;
53template struct armnn::ElementwiseBinaryFunction<std::less<float>>;
54template struct armnn::ElementwiseBinaryFunction<std::less_equal<float>>;
55template struct armnn::ElementwiseBinaryFunction<std::not_equal_to<float>>;
56
57// Unary
58template struct armnn::ElementwiseUnaryFunction<armnn::abs<float>>;
59template struct armnn::ElementwiseUnaryFunction<armnn::exp<float>>;
60template struct armnn::ElementwiseUnaryFunction<std::negate<float>>;
61template struct armnn::ElementwiseUnaryFunction<armnn::rsqrt<float>>;
62template struct armnn::ElementwiseUnaryFunction<armnn::sqrt<float>>;