blob: 9887e423863a386508950f0c71ef6ba8865cd95a [file] [log] [blame]
Anthony Barbier8140e1e2017-12-14 23:48:46 +00001/*
Jenkins52ba29e2018-08-29 15:32:11 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier8140e1e2017-12-14 23:48:46 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "ActivationLayer.h"
25
26#include "arm_compute/core/Types.h"
Anthony Barbier8140e1e2017-12-14 23:48:46 +000027#include "tests/validation/Helpers.h"
28
29namespace arm_compute
30{
31namespace test
32{
33namespace validation
34{
35namespace reference
36{
Jenkinsb9abeae2018-11-22 11:58:08 +000037template <typename T>
Anthony Barbier8140e1e2017-12-14 23:48:46 +000038SimpleTensor<T> activation_layer(const SimpleTensor<T> &src, ActivationLayerInfo info)
39{
40 // Create reference
Jenkins52ba29e2018-08-29 15:32:11 +000041 SimpleTensor<T> dst{ src.shape(), src.data_type(), 1 };
Anthony Barbier8140e1e2017-12-14 23:48:46 +000042
43 // Compute reference
44 const T a(info.a());
45 const T b(info.b());
46
47 for(int i = 0; i < src.num_elements(); ++i)
48 {
Jenkinsb9abeae2018-11-22 11:58:08 +000049 dst[i] = activate_float<T>(src[i], a, b, info.activation());
Anthony Barbier8140e1e2017-12-14 23:48:46 +000050 }
51
52 return dst;
53}
54
Anthony Barbier8140e1e2017-12-14 23:48:46 +000055template <>
56SimpleTensor<uint8_t> activation_layer<uint8_t>(const SimpleTensor<uint8_t> &src, ActivationLayerInfo info)
57{
58 SimpleTensor<float> src_tmp = convert_from_asymmetric(src);
59 SimpleTensor<float> dst_tmp = activation_layer<float>(src_tmp, info);
60 SimpleTensor<uint8_t> dst = convert_to_asymmetric(dst_tmp, src.quantization_info());
61 return dst;
62}
63
64template SimpleTensor<float> activation_layer(const SimpleTensor<float> &src, ActivationLayerInfo info);
65template SimpleTensor<half> activation_layer(const SimpleTensor<half> &src, ActivationLayerInfo info);
Anthony Barbier8140e1e2017-12-14 23:48:46 +000066} // namespace reference
67} // namespace validation
68} // namespace test
69} // namespace arm_compute