FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/lls.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 37 42 88.1%
Functions: 3 3 100.0%
Branches: 29 46 63.0%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <float.h>
20 #include "libavutil/lls.h"
21 #include "checkasm.h"
22
23 #define randomize_buffer(buf) \
24 do { \
25 double bmg[2], stddev = 10.0; \
26 \
27 for (size_t i = 0; i < MAX_VARS_ALIGN; i += 2) { \
28 av_bmg_get(&checkasm_lfg, bmg); \
29 buf[i] = bmg[0] * stddev; \
30 buf[i + 1] = bmg[1] * stddev; \
31 } \
32 } while(0);
33
34 12 static void test_update(LLSModel *lls, const double *var)
35 {
36 double refcovar[MAX_VARS][MAX_VARS];
37 12 declare_func(void, LLSModel *, const double *);
38
39 12 call_ref(lls, var);
40
41
2/2
✓ Branch 0 taken 384 times.
✓ Branch 1 taken 12 times.
396 for (size_t i = 0; i < MAX_VARS; i++)
42
2/2
✓ Branch 0 taken 12288 times.
✓ Branch 1 taken 384 times.
12672 for (size_t j = 0; j < MAX_VARS; j++)
43 12288 refcovar[i][j] = lls->covariance[i][j];
44
45 12 memset(lls->covariance, 0, sizeof (lls->covariance));
46 12 call_new(lls, var);
47
48
2/2
✓ Branch 0 taken 208 times.
✓ Branch 1 taken 12 times.
220 for (size_t i = 0; i < lls->indep_count; i++)
49
2/2
✓ Branch 0 taken 2568 times.
✓ Branch 1 taken 208 times.
2776 for (size_t j = i; j < lls->indep_count; j++) {
50
2/2
✓ Branch 0 taken 2306 times.
✓ Branch 1 taken 262 times.
2568 double eps = FFMAX(2 * DBL_EPSILON * fabs(refcovar[i][j]),
51 8 * DBL_EPSILON);
52
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2568 times.
2568 if (!double_near_abs_eps(refcovar[i][j], lls->covariance[i][j],
53 eps)) {
54 fprintf(stderr, "%zu, %zu: %- .12f - %- .12f = % .12g\n", i, j,
55 refcovar[i][j], lls->covariance[i][j],
56 refcovar[i][j] - lls->covariance[i][j]);
57 fail();
58 }
59 }
60
61
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
12 bench_new(lls, var);
62 12 }
63
64 12 static void test_evaluate(LLSModel *lls, const double *param, int order)
65 {
66 double refprod, newprod, eps;
67 12 declare_func_float(double, LLSModel *, const double *, int);
68
69 12 refprod = call_ref(lls, param, order);
70 12 newprod = call_new(lls, param, order);
71
72
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 eps = FFMAX(2 * DBL_EPSILON * fabs(refprod), 0.2);
73
74
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
12 if (!double_near_abs_eps(refprod, newprod, eps)) {
75 fprintf(stderr, "%- .12f - %- .12f = % .12g\n",
76 refprod, newprod, refprod - newprod);
77 fail();
78 }
79
80
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 if (order == lls->indep_count)
81
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
6 bench_new(lls, param, order);
82 12 }
83
84 13 void checkasm_check_lls(void)
85 {
86 static const unsigned char counts[] = { 8, 12, MAX_VARS, };
87
88
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 13 times.
52 for (size_t i = 0; i < FF_ARRAY_ELEMS(counts); i++) {
89 39 LOCAL_ALIGNED_32(double, var, [MAX_VARS_ALIGN]);
90 39 LOCAL_ALIGNED_32(double, param, [FFALIGN(MAX_VARS+2,4)]);
91 LLSModel lls;
92
93 39 avpriv_init_lls(&lls, counts[i]);
94
2/2
✓ Branch 1 taken 702 times.
✓ Branch 2 taken 39 times.
741 randomize_buffer(var);
95
2/2
✓ Branch 1 taken 702 times.
✓ Branch 2 taken 39 times.
741 randomize_buffer(param);
96
97
2/2
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 27 times.
39 if (check_func(lls.update_lls, "update_lls_%d", counts[i]))
98 12 test_update(&lls, var);
99
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 39 times.
117 for (size_t j = 0; j <= i; j++)
100
2/2
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 66 times.
78 if (check_func(lls.evaluate_lls, "evaluate_lls_%d_%d", counts[i],
101 counts[j]))
102 12 test_evaluate(&lls, param + 1, counts[j]);
103 }
104 13 report("lls");
105 13 }
106