FFmpeg
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 "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 static void test_update(LLSModel *lls, const double *var)
35 {
36  double refcovar[MAX_VARS][MAX_VARS];
37  declare_func(void, LLSModel *, const double *);
38 
39  call_ref(lls, var);
40 
41  for (size_t i = 0; i < MAX_VARS; i++)
42  for (size_t j = 0; j < MAX_VARS; j++)
43  refcovar[i][j] = lls->covariance[i][j];
44 
45  memset(lls->covariance, 0, sizeof (lls->covariance));
46  call_new(lls, var);
47 
48  for (size_t i = 0; i < lls->indep_count; i++)
49  for (size_t j = i; j < lls->indep_count; j++)
50  if (!double_near_abs_eps(refcovar[i][j], lls->covariance[i][j],
51  8 * DBL_EPSILON)) {
52  fprintf(stderr, "%zu, %zu: %- .12f - %- .12f = % .12g\n", i, j,
53  refcovar[i][j], lls->covariance[i][j],
54  refcovar[i][j] - lls->covariance[i][j]);
55  fail();
56  }
57 
58  bench_new(lls, var);
59 }
60 
61 #define EPS 0.2
62 static void test_evaluate(LLSModel *lls, const double *param, int order)
63 {
64  double refprod, newprod;
65  declare_func_float(double, LLSModel *, const double *, int);
66 
67  refprod = call_ref(lls, param, order);
68  newprod = call_new(lls, param, order);
69 
70  if (!double_near_abs_eps(refprod, newprod, EPS)) {
71  fprintf(stderr, "%- .12f - %- .12f = % .12g\n",
72  refprod, newprod, refprod - newprod);
73  fail();
74  }
75 
76  if (order == lls->indep_count)
77  bench_new(lls, param, order);
78 }
79 
81 {
82  static const unsigned char counts[] = { 8, 12, MAX_VARS, };
83 
84  for (size_t i = 0; i < FF_ARRAY_ELEMS(counts); i++) {
85  LOCAL_ALIGNED_32(double, var, [MAX_VARS_ALIGN]);
86  LOCAL_ALIGNED_32(double, param, [FFALIGN(MAX_VARS+2,4)]);
87  LLSModel lls;
88 
89  avpriv_init_lls(&lls, counts[i]);
90  randomize_buffer(var);
91  randomize_buffer(param);
92 
93  if (check_func(lls.update_lls, "update_lls_%d", counts[i]))
94  test_update(&lls, var);
95  for (size_t j = 0; j <= i; j++)
96  if (check_func(lls.evaluate_lls, "evaluate_lls_%d_%d", counts[i],
97  counts[j]))
98  test_evaluate(&lls, param + 1, counts[j]);
99  }
100  report("lls");
101 }
LLSModel
Linear least squares model.
Definition: lls.h:37
test_update
static void test_update(LLSModel *lls, const double *var)
Definition: lls.c:34
MAX_VARS_ALIGN
#define MAX_VARS_ALIGN
Definition: lls.h:30
MAX_VARS
#define MAX_VARS
Definition: lls.h:29
check_func
#define check_func(func,...)
Definition: checkasm.h:179
float.h
declare_func_float
#define declare_func_float(ret,...)
Definition: checkasm.h:184
call_ref
#define call_ref(...)
Definition: checkasm.h:194
double_near_abs_eps
int double_near_abs_eps(double a, double b, double eps)
Definition: checkasm.c:478
fail
#define fail()
Definition: checkasm.h:188
checkasm.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
lls.h
checkasm_check_lls
void checkasm_check_lls(void)
Definition: lls.c:80
call_new
#define call_new(...)
Definition: checkasm.h:297
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:156
LLSModel::update_lls
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
EPS
#define EPS
Definition: lls.c:61
LLSModel::evaluate_lls
double(* evaluate_lls)(struct LLSModel *m, const double *var, int order)
Inner product of var[] and the LPC coefs.
Definition: lls.h:56
LLSModel::indep_count
int indep_count
Definition: lls.h:41
report
#define report
Definition: checkasm.h:191
bench_new
#define bench_new(...)
Definition: checkasm.h:368
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
randomize_buffer
#define randomize_buffer(buf)
Definition: lls.c:23
avpriv_init_lls
av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
Definition: lls.c:109
LLSModel::covariance
double covariance[(((32+1)+(4) -1)&~((4) -1))][MAX_VARS_ALIGN]
Definition: lls.h:38
test_evaluate
static void test_evaluate(LLSModel *lls, const double *param, int order)
Definition: lls.c:62
declare_func
#define declare_func(ret,...)
Definition: checkasm.h:183
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78