blob: 31c05a678dd02ccf9e6c24ed3d9f2c7c2eeab166 [file] [log] [blame]
Jan Eilers3812fbc2020-11-17 19:06:35 +00001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "TestUtils.hpp"
7
8namespace armnnDelegate
9{
10
Jan Eilersb33f28b2020-11-18 10:36:46 +000011
12
13void CompareData(bool tensor1[], bool tensor2[], size_t tensorSize)
14{
15 auto compareBool = [](auto a, auto b) {return (((a == 0) && (b == 0)) || ((a != 0) && (b != 0)));};
16 for (size_t i = 0; i < tensorSize; i++)
17 {
18 CHECK(compareBool(tensor1[i], tensor2[i]));
19 }
20}
21
22void CompareData(std::vector<bool>& tensor1, bool tensor2[], size_t tensorSize)
23{
24 auto compareBool = [](auto a, auto b) {return (((a == 0) && (b == 0)) || ((a != 0) && (b != 0)));};
25 for (size_t i = 0; i < tensorSize; i++)
26 {
27 CHECK(compareBool(tensor1[i], tensor2[i]));
28 }
29}
30
Jan Eilers3812fbc2020-11-17 19:06:35 +000031void CompareData(float tensor1[], float tensor2[], size_t tensorSize)
32{
33 for (size_t i = 0; i < tensorSize; i++)
34 {
35 CHECK(tensor1[i] == doctest::Approx( tensor2[i] ));
36 }
37}
38
39void CompareData(uint8_t tensor1[], uint8_t tensor2[], size_t tensorSize)
40{
41 uint8_t tolerance = 1;
42 for (size_t i = 0; i < tensorSize; i++)
43 {
44 CHECK(std::max(tensor1[i], tensor2[i]) - std::min(tensor1[i], tensor2[i]) <= tolerance);
45 }
46}
47
48void CompareData(int16_t tensor1[], int16_t tensor2[], size_t tensorSize)
49{
50 int16_t tolerance = 1;
51 for (size_t i = 0; i < tensorSize; i++)
52 {
53 CHECK(std::max(tensor1[i], tensor2[i]) - std::min(tensor1[i], tensor2[i]) <= tolerance);
54 }
55}
56
57void CompareData(int8_t tensor1[], int8_t tensor2[], size_t tensorSize)
58{
59 int8_t tolerance = 1;
60 for (size_t i = 0; i < tensorSize; i++)
61 {
62 CHECK(std::max(tensor1[i], tensor2[i]) - std::min(tensor1[i], tensor2[i]) <= tolerance);
63 }
64}
65
66} // namespace armnnDelegate