FFmpeg
Loading...
Searching...
No Matches
lls.c
Go to the documentation of this file.
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 <stdio.h>
21#include <string.h>
22
23#include "libavutil/lls.h"
24#include "checkasm.h"
25
26static void test_update(LLSModel *lls, const double *var)
27{
28 double refcovar[MAX_VARS][MAX_VARS];
29 declare_func(void, LLSModel *, const double *);
30
31 call_ref(lls, var);
32
33 for (size_t i = 0; i < MAX_VARS; i++)
34 for (size_t j = 0; j < MAX_VARS; j++)
35 refcovar[i][j] = lls->covariance[i][j];
36
37 memset(lls->covariance, 0, sizeof (lls->covariance));
38 call_new(lls, var);
39
40 for (size_t i = 0; i < lls->indep_count; i++)
41 for (size_t j = i; j < lls->indep_count; j++) {
42 double eps = FFMAX(2 * DBL_EPSILON * fabs(refcovar[i][j]),
43 8 * DBL_EPSILON);
44 if (!double_near_abs_eps(refcovar[i][j], lls->covariance[i][j],
45 eps)) {
46 fprintf(stderr, "%zu, %zu: %- .12f - %- .12f = % .12g\n", i, j,
47 refcovar[i][j], lls->covariance[i][j],
48 refcovar[i][j] - lls->covariance[i][j]);
49 fail();
50 }
51 }
52
53 bench_new(lls, var);
54}
55
56static void test_evaluate(LLSModel *lls, const double *param, int order)
57{
58 double refprod, newprod, eps;
59 declare_func_float(double, LLSModel *, const double *, int);
60
61 refprod = call_ref(lls, param, order);
62 newprod = call_new(lls, param, order);
63
64 eps = FFMAX(2 * DBL_EPSILON * fabs(refprod), 0.2);
65
66 if (!double_near_abs_eps(refprod, newprod, eps)) {
67 fprintf(stderr, "%- .12f - %- .12f = % .12g\n",
68 refprod, newprod, refprod - newprod);
69 fail();
70 }
71
72 if (order == lls->indep_count)
73 bench_new(lls, param, order);
74}
75
77{
78 static const unsigned char counts[] = { 8, 12, MAX_VARS, };
79
80 for (size_t i = 0; i < FF_ARRAY_ELEMS(counts); i++) {
81 LOCAL_ALIGNED_32(double, var, [MAX_VARS_ALIGN]);
82 LOCAL_ALIGNED_32(double, param, [FFALIGN(MAX_VARS+2,4)]);
83 LLSModel lls;
84
85 avpriv_init_lls(&lls, counts[i]);
88
89 if (check_func(lls.update_lls, "update_lls_%d", counts[i]))
90 test_update(&lls, var);
91 for (size_t j = 0; j <= i; j++)
92 if (check_func(lls.evaluate_lls, "evaluate_lls_%d_%d", counts[i],
93 counts[j]))
94 test_evaluate(&lls, param + 1, counts[j]);
95 }
96 report("lls");
97}
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define declare_func_float
Definition checkasm.h:136
#define randomize_stddev_dbl(buf, size, stddev)
Definition checkasm.h:141
static __device__ float fabs(float a)
#define declare_func
Definition test.h:489
#define fail
Definition test.h:479
#define bench_new
Definition test.h:487
#define check_func
Definition test.h:481
#define call_new
Definition test.h:486
#define call_ref
Definition test.h:485
#define report
Definition test.h:480
#define double_near_abs_eps
Definition utils.h:454
av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
Definition lls.c:109
#define MAX_VARS
Definition lls.h:29
#define MAX_VARS_ALIGN
Definition lls.h:30
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
#define LOCAL_ALIGNED_32(t, v,...)
#define FF_ARRAY_ELEMS(a)
Linear least squares model.
Definition lls.h:37
void(* update_lls)(struct LLSModel *m, const double *var)
Take the outer-product of var[] with itself, and add to the covariance matrix.
Definition lls.h:49
double(* evaluate_lls)(struct LLSModel *m, const double *var, int order)
Inner product of var[] and the LPC coefs.
Definition lls.h:56
int indep_count
Definition lls.h:41
double covariance[MAX_VARS_ALIGN][MAX_VARS_ALIGN]
Definition lls.h:38
static void test_update(LLSModel *lls, const double *var)
Definition lls.c:26
static void test_evaluate(LLSModel *lls, const double *param, int order)
Definition lls.c:56
void checkasm_check_lls(void)
Definition lls.c:76