aboutsummaryrefslogtreecommitdiffstats
path: root/tests/checkasm/lls.c
diff options
context:
space:
mode:
authorRémi Denis-Courmont <remi@remlab.net>2024-05-28 22:56:34 +0300
committerRémi Denis-Courmont <remi@remlab.net>2024-06-01 18:05:58 +0300
commitfc85aff72f197d07751ef76cf4e9744f720d9f3e (patch)
treed0e2f4b74623fd80f3d7e070c5dcd9dc115ff27b /tests/checkasm/lls.c
parent7087da303f9ae638f54134b1ac5f621ecf7e1171 (diff)
downloadffmpeg-fc85aff72f197d07751ef76cf4e9744f720d9f3e.tar.gz
checkasm: add linear least square tests
Diffstat (limited to 'tests/checkasm/lls.c')
-rw-r--r--tests/checkasm/lls.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/checkasm/lls.c b/tests/checkasm/lls.c
new file mode 100644
index 0000000000..a2e8f11f99
--- /dev/null
+++ b/tests/checkasm/lls.c
@@ -0,0 +1,101 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <float.h>
+#include "libavutil/lls.h"
+#include "checkasm.h"
+
+#define randomize_buffer(buf) \
+do { \
+ double bmg[2], stddev = 10.0; \
+ \
+ for (size_t i = 0; i < MAX_VARS; i += 2) { \
+ av_bmg_get(&checkasm_lfg, bmg); \
+ buf[i] = bmg[0] * stddev; \
+ buf[i + 1] = bmg[1] * stddev; \
+ } \
+} while(0);
+
+static void test_update(LLSModel *lls, const double *var)
+{
+ double refcovar[MAX_VARS][MAX_VARS];
+ declare_func(void, LLSModel *, const double *);
+
+ call_ref(lls, var);
+
+ for (size_t i = 0; i < MAX_VARS; i++)
+ for (size_t j = 0; j < MAX_VARS; j++)
+ refcovar[i][j] = lls->covariance[i][j];
+
+ memset(lls->covariance, 0, sizeof (lls->covariance));
+ call_new(lls, var);
+
+ for (size_t i = 0; i < lls->indep_count; i++)
+ for (size_t j = i; j < lls->indep_count; j++)
+ if (!double_near_abs_eps(refcovar[i][j], lls->covariance[i][j],
+ 2 * DBL_EPSILON)) {
+ fprintf(stderr, "%zu, %zu: %- .12f - %- .12f = % .12g\n", i, j,
+ refcovar[i][j], lls->covariance[i][j],
+ refcovar[i][j] - lls->covariance[i][j]);
+ fail();
+ }
+
+ bench_new(lls, var);
+}
+
+#define EPS 0.2
+static void test_evaluate(LLSModel *lls, const double *param, int order)
+{
+ double refprod, newprod;
+ declare_func_float(double, LLSModel *, const double *, int);
+
+ refprod = call_ref(lls, param, order);
+ newprod = call_new(lls, param, order);
+
+ if (!double_near_abs_eps(refprod, newprod, EPS)) {
+ fprintf(stderr, "%- .12f - %- .12f = % .12g\n",
+ refprod, newprod, refprod - newprod);
+ fail();
+ }
+
+ if (order == lls->indep_count)
+ bench_new(lls, param, order);
+}
+
+void checkasm_check_lls(void)
+{
+ static const unsigned char counts[] = { 8, 12, MAX_VARS, };
+
+ for (size_t i = 0; i < FF_ARRAY_ELEMS(counts); i++) {
+ LOCAL_ALIGNED_32(double, var, [MAX_VARS]);
+ LOCAL_ALIGNED_32(double, param, [MAX_VARS]);
+ LLSModel lls;
+
+ avpriv_init_lls(&lls, counts[i]);
+ randomize_buffer(var);
+ randomize_buffer(param);
+
+ if (check_func(lls.update_lls, "update_lls_%d", counts[i]))
+ test_update(&lls, var);
+ for (size_t j = 0; j <= i; j++)
+ if (check_func(lls.evaluate_lls, "evaluate_lls_%d_%d", counts[i],
+ counts[j]))
+ test_evaluate(&lls, param, counts[j]);
+ }
+ report("lls");
+}