blob: c46376b80e09f32ae6b658e54b9667b76bd545e0 [file] [log] [blame]
Aron Virginas-Tar8fccd862019-09-09 11:22:56 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include "CommonTestUtils.hpp"
9
10#include <ResolveType.hpp>
11
12#include <armnn/ArmNN.hpp>
13
14namespace
15{
16
17armnn::INetworkPtr CreateAbsNetwork(const armnn::TensorInfo& tensorInfo)
18{
19 armnn::INetworkPtr network(armnn::INetwork::Create());
20
21 armnn::IConnectableLayer* inputLayer = network->AddInputLayer(0, "input");
22 armnn::IConnectableLayer* absLayer = network->AddAbsLayer("abs");
23 armnn::IConnectableLayer* outputLayer = network->AddOutputLayer(0, "output");
24
25 Connect(inputLayer, absLayer, tensorInfo, 0, 0);
26 Connect(absLayer, outputLayer, tensorInfo, 0, 0);
27
28 return network;
29}
30
31} // anonymous namespace
32
33template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
34void AbsEndToEnd(const std::vector<armnn::BackendId>& backends)
35{
36 using namespace armnn;
37
38 const float qScale = IsQuantizedType<T>() ? 0.25f : 1.0f;
39 const int32_t qOffset = IsQuantizedType<T>() ? 50 : 0;
40
41 TensorInfo tensorInfo({ 1, 1, 2, 3 }, ArmnnType, qScale, qOffset);
42
43 std::vector<float> inputData =
44 {
45 -1.f, 2.f, -3.f,
46 4.f, -5.f, 6.f
47 };
48
49 std::vector<float> expectedOutputData =
50 {
51 1.f, 2.f, 3.f,
52 4.f, 5.f, 6.f
53 };
54
55 // quantize data
56 std::vector<T> qInputData = QuantizedVector<T>(qScale, qOffset, inputData);
57 std::vector<T> qExpectedOutputData = QuantizedVector<T>(qScale, qOffset, expectedOutputData);
58
59 INetworkPtr network = CreateAbsNetwork(tensorInfo);
60
61 EndToEndLayerTestImpl<ArmnnType, ArmnnType>(std::move(network),
62 { { 0, qInputData } },
63 { { 0, qExpectedOutputData } },
64 backends);
65}