Colm Donelan | d047262 | 2023-03-06 12:34:54 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2023 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "../NetworkExecutionUtils.hpp" |
| 7 | |
| 8 | #include <doctest/doctest.h> |
| 9 | |
| 10 | namespace |
| 11 | { |
| 12 | |
| 13 | TEST_SUITE("NetworkExecutionUtilsTests") |
| 14 | { |
| 15 | |
| 16 | TEST_CASE ("ComputeByteLevelRMSE") |
| 17 | { |
| 18 | // Bytes. |
| 19 | const uint8_t expected[] = {1, 128, 255}; |
| 20 | const uint8_t actual[] = {0, 127, 254}; |
| 21 | |
| 22 | CHECK(ComputeByteLevelRMSE(expected, expected, 3) == 0); |
| 23 | CHECK(ComputeByteLevelRMSE(expected, actual, 3) == 1.0); |
| 24 | |
| 25 | // Floats. |
| 26 | const float expectedFloat[] = |
| 27 | {55.20419, 24.58061, 67.76520, 47.31617, 55.58102, 44.64565, 105.76307, 54.65538, 80.41088, 66.05208}; |
| 28 | const float actualFloat[] = |
| 29 | {13.87187, 14.16160, 49.28846, 25.89192, 97.70659, 91.30055, 15.88831, 4.79960, 102.99205, 51.28290}; |
| 30 | const double expectedResult = 74.059098023; // Calculated manually. |
| 31 | CHECK(ComputeByteLevelRMSE(expectedFloat, expectedFloat, sizeof(float) * 10) == 0); |
| 32 | CHECK(ComputeByteLevelRMSE(expectedFloat, actualFloat, sizeof(float) * 10) == doctest::Approx(expectedResult)); |
| 33 | } |
| 34 | |
| 35 | } // End of TEST_SUITE("NetworkExecutionUtilsTests") |
| 36 | |
| 37 | } // anonymous namespace |