aboutsummaryrefslogtreecommitdiff
path: root/delegate/src/test/TestUtils.cpp
blob: 31c05a678dd02ccf9e6c24ed3d9f2c7c2eeab166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//
// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "TestUtils.hpp"

namespace armnnDelegate
{



void CompareData(bool tensor1[], bool tensor2[], size_t tensorSize)
{
    auto compareBool = [](auto a, auto b) {return (((a == 0) && (b == 0)) || ((a != 0) && (b != 0)));};
    for (size_t i = 0; i < tensorSize; i++)
    {
        CHECK(compareBool(tensor1[i], tensor2[i]));
    }
}

void CompareData(std::vector<bool>& tensor1, bool tensor2[], size_t tensorSize)
{
    auto compareBool = [](auto a, auto b) {return (((a == 0) && (b == 0)) || ((a != 0) && (b != 0)));};
    for (size_t i = 0; i < tensorSize; i++)
    {
        CHECK(compareBool(tensor1[i], tensor2[i]));
    }
}

void CompareData(float tensor1[], float tensor2[], size_t tensorSize)
{
    for (size_t i = 0; i < tensorSize; i++)
    {
        CHECK(tensor1[i] == doctest::Approx( tensor2[i] ));
    }
}

void CompareData(uint8_t tensor1[], uint8_t tensor2[], size_t tensorSize)
{
    uint8_t tolerance = 1;
    for (size_t i = 0; i < tensorSize; i++)
    {
        CHECK(std::max(tensor1[i], tensor2[i]) - std::min(tensor1[i], tensor2[i]) <= tolerance);
    }
}

void CompareData(int16_t tensor1[], int16_t tensor2[], size_t tensorSize)
{
    int16_t tolerance = 1;
    for (size_t i = 0; i < tensorSize; i++)
    {
        CHECK(std::max(tensor1[i], tensor2[i]) - std::min(tensor1[i], tensor2[i]) <= tolerance);
    }
}

void CompareData(int8_t tensor1[], int8_t tensor2[], size_t tensorSize)
{
    int8_t tolerance = 1;
    for (size_t i = 0; i < tensorSize; i++)
    {
        CHECK(std::max(tensor1[i], tensor2[i]) - std::min(tensor1[i], tensor2[i]) <= tolerance);
    }
}

} // namespace armnnDelegate