aboutsummaryrefslogtreecommitdiff
path: root/reference_model/test/verify_tests.cpp
blob: f43804fe0c34e2f064fa00a2d55a018fce17180c (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
// Copyright (c) 2023, ARM Limited.
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//         http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.
#include "verify.h"

#include <doctest.h>

#include <array>
#include <numeric>
#include <vector>

TEST_SUITE("verify")
{
    TEST_CASE("check_element_accfp32")
    {
        const size_t KS = 27;

        // Negative (bnd == 0.0)
        REQUIRE_FALSE(tosa_validate_element_accfp32(0.0, 0.0, 1.0, KS).is_valid);
        REQUIRE_FALSE(tosa_validate_element_accfp32(1.0, 0.0, 0.0, KS).is_valid);
        // Negative (bnd > 0.0)
        REQUIRE_FALSE(tosa_validate_element_accfp32(5.0, 5.0, 5.1, KS).is_valid);

        // Positive (bnd == 0.0 && ref == 0.0 && imp == 0.0)
        REQUIRE(tosa_validate_element_accfp32(0.0, 0.0, 0.0, KS).is_valid);
        REQUIRE(tosa_validate_element_accfp32(0.0, 0.0, 0.0, KS).error == 0.0);

        // Positive (bnd > 0.0)
        REQUIRE(tosa_validate_element_accfp32(4.0, 4.0, 4.0, KS).error == 0.0);
        REQUIRE(tosa_validate_element_accfp32(4.0, 4.0, 4.0, KS).error == 0.0);
        REQUIRE(tosa_validate_element_accfp32(4.0, 4.0, 4.0, KS).error == 0.0);
    }
    TEST_CASE("check_output_error")
    {
        const size_t KS = 27;
        const size_t T  = 1024;

        // Negative (S!=1 && S!=2 && (abs(err_sum) > 2*sqrt(KS*T)))
        REQUIRE_FALSE(tosa_validate_output_error(1560, 112000, KS, T, 0));
        // Negative (err_sum_sq > 0.4*KS*T))
        REQUIRE_FALSE(tosa_validate_output_error(1560, 112000, KS, T, 1));
        // Positive
        REQUIRE(tosa_validate_output_error(10, 254, KS, T, 0));
        REQUIRE(tosa_validate_output_error(10, 254, KS, T, 1));
    }
}