Jan Eilers | 3812fbc | 2020-11-17 19:06:35 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "TestUtils.hpp" |
| 7 | |
| 8 | namespace armnnDelegate |
| 9 | { |
| 10 | |
Jan Eilers | b33f28b | 2020-11-18 10:36:46 +0000 | [diff] [blame] | 11 | |
| 12 | |
| 13 | void 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 | |
| 22 | void 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 Eilers | 3812fbc | 2020-11-17 19:06:35 +0000 | [diff] [blame] | 31 | void 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 | |
| 39 | void 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 | |
| 48 | void 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 | |
| 57 | void 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 |