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 static void test_update(LLSModel *lls, const double *var)
24 {
25  double refcovar[MAX_VARS][MAX_VARS];
26  declare_func(void, LLSModel *, const double *);
27 
28  call_ref(lls, var);
29 
30  for (size_t i = 0; i < MAX_VARS; i++)
31  for (size_t j = 0; j < MAX_VARS; j++)
32  refcovar[i][j] = lls->covariance[i][j];
33 
34  memset(lls->covariance, 0, sizeof (lls->covariance));
35  call_new(lls, var);
36 
37  for (size_t i = 0; i < lls->indep_count; i++)
38  for (size_t j = i; j < lls->indep_count; j++) {
39  double eps = FFMAX(2 * DBL_EPSILON * fabs(refcovar[i][j]),
40  8 * DBL_EPSILON);
41  if (!double_near_abs_eps(refcovar[i][j], lls->covariance[i][j],
42  eps)) {
43  fprintf(stderr, "%zu, %zu: %- .12f - %- .12f = % .12g\n", i, j,
44  refcovar[i][j], lls->covariance[i][j],
45  refcovar[i][j] - lls->covariance[i][j]);
46  fail();
47  }
48  }
49 
50  bench_new(lls, var);
51 }
52 
53 static void test_evaluate(LLSModel *lls, const double *param, int order)
54 {
55  double refprod, newprod, eps;
56  declare_func_float(double, LLSModel *, const double *, int);
57 
58  refprod = call_ref(lls, param, order);
59  newprod = call_new(lls, param, order);
60 
61  eps = FFMAX(2 * DBL_EPSILON * fabs(refprod), 0.2);
62 
63  if (!double_near_abs_eps(refprod, newprod, eps)) {
64  fprintf(stderr, "%- .12f - %- .12f = % .12g\n",
65  refprod, newprod, refprod - newprod);
66  fail();
67  }
68 
69  if (order == lls->indep_count)
70  bench_new(lls, param, order);
71 }
72 
74 {
75  static const unsigned char counts[] = { 8, 12, MAX_VARS, };
76 
77  for (size_t i = 0; i < FF_ARRAY_ELEMS(counts); i++) {
78  LOCAL_ALIGNED_32(double, var, [MAX_VARS_ALIGN]);
79  LOCAL_ALIGNED_32(double, param, [FFALIGN(MAX_VARS+2,4)]);
80  LLSModel lls;
81 
82  avpriv_init_lls(&lls, counts[i]);
85 
86  if (check_func(lls.update_lls, "update_lls_%d", counts[i]))
87  test_update(&lls, var);
88  for (size_t j = 0; j <= i; j++)
89  if (check_func(lls.evaluate_lls, "evaluate_lls_%d_%d", counts[i],
90  counts[j]))
91  test_evaluate(&lls, param + 1, counts[j]);
92  }
93  report("lls");
94 }
LLSModel
Linear least squares model.
Definition: lls.h:37
test_update
static void test_update(LLSModel *lls, const double *var)
Definition: lls.c:23
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
Definition: test.h:480
float.h
bench_new
#define bench_new
Definition: test.h:486
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
call_ref
#define call_ref
Definition: test.h:484
checkasm.h
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
declare_func
#define declare_func
Definition: test.h:488
lls.h
checkasm_check_lls
void checkasm_check_lls(void)
Definition: lls.c:73
fail
#define fail
Definition: test.h:478
fabs
static __device__ float fabs(float a)
Definition: cuda_runtime.h:182
LOCAL_ALIGNED_32
#define LOCAL_ALIGNED_32(t, v,...)
Definition: mem_internal.h:132
randomize_stddev_dbl
#define randomize_stddev_dbl(buf, size, stddev)
Definition: checkasm.h:146
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
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
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
declare_func_float
#define declare_func_float
Definition: checkasm.h:141
avpriv_init_lls
av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
Definition: lls.c:109
call_new
#define call_new
Definition: test.h:485
LLSModel::covariance
double covariance[(((32+1)+(4) -1)&~((4) -1))][MAX_VARS_ALIGN]
Definition: lls.h:38
double_near_abs_eps
#define double_near_abs_eps
Definition: utils.h:376
test_evaluate
static void test_evaluate(LLSModel *lls, const double *param, int order)
Definition: lls.c:53
report
#define report
Definition: test.h:479
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78