]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/lls.c
configure: Add check_cc/require_cc helper functions to simplify some expressions
[ffmpeg] / libavutil / lls.c
index a26b3c23d9b6f75aa74e4b81d827912ae2021774..97bffb4018fdf0533580a94a8ed927e36c5afb02 100644 (file)
 #include <math.h>
 #include <string.h>
 
+#include "attributes.h"
+#include "internal.h"
+#include "version.h"
 #include "lls.h"
 
-void avpriv_init_lls(LLSModel *m, int indep_count)
-{
-    memset(m, 0, sizeof(LLSModel));
-    m->indep_count = indep_count;
-}
-
-void avpriv_update_lls(LLSModel *m, double *var, double decay)
+static void update_lls(LLSModel *m, double *var)
 {
     int i, j;
 
     for (i = 0; i <= m->indep_count; i++) {
         for (j = i; j <= m->indep_count; j++) {
-            m->covariance[i][j] *= decay;
             m->covariance[i][j] += var[i] * var[j];
         }
     }
@@ -51,8 +47,8 @@ void avpriv_update_lls(LLSModel *m, double *var, double decay)
 void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
 {
     int i, j, k;
-    double (*factor)[MAX_VARS + 1] = (void *) &m->covariance[1][0];
-    double (*covar) [MAX_VARS + 1] = (void *) &m->covariance[1][1];
+    double (*factor)[MAX_VARS_ALIGN] = (void *) &m->covariance[1][0];
+    double (*covar) [MAX_VARS_ALIGN] = (void *) &m->covariance[1][1];
     double *covar_y                = m->covariance[0];
     int count                      = m->indep_count;
 
@@ -105,7 +101,7 @@ void avpriv_solve_lls(LLSModel *m, double threshold, unsigned short min_order)
     }
 }
 
-double avpriv_evaluate_lls(LLSModel *m, double *param, int order)
+static double evaluate_lls(LLSModel *m, double *param, int order)
 {
     int i;
     double out = 0;
@@ -116,59 +112,12 @@ double avpriv_evaluate_lls(LLSModel *m, double *param, int order)
     return out;
 }
 
-#ifndef FF_API_LLS_PRIVATE
-void av_init_lls(LLSModel *m, int indep_count)
-{
-    return avpriv_init_lls(m, indep_count);
-}
-void av_update_lls(LLSModel *m, double *param, double decay)
-{
-    return avpriv_update_lls(m, param, decay);
-}
-void av_solve_lls(LLSModel *m, double threshold, int min_order)
-{
-    return avpriv_solve_lls(m, threshold, min_order);
-}
-double av_evaluate_lls(LLSModel *m, double *param, int order)
+av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
 {
-    return avpriv_evaluate_lls(m, param, order);
-}
-#endif
-
-#ifdef TEST
-
-#include <stdio.h>
-#include <limits.h>
-#include "lfg.h"
-
-int main(void)
-{
-    LLSModel m;
-    int i, order;
-    AVLFG lfg;
-
-    av_lfg_init(&lfg, 1);
-    avpriv_init_lls(&m, 3);
-
-    for (i = 0; i < 100; i++) {
-        double var[4];
-        double eval;
-
-        var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2;
-        var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
-        var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
-        var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5;
-        avpriv_update_lls(&m, var, 0.99);
-        avpriv_solve_lls(&m, 0.001, 0);
-        for (order = 0; order < 3; order++) {
-            eval = avpriv_evaluate_lls(&m, var + 1, order);
-            printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n",
-                   var[0], order, eval, sqrt(m.variance[order] / (i + 1)),
-                   m.coeff[order][0], m.coeff[order][1],
-                   m.coeff[order][2]);
-        }
-    }
-    return 0;
+    memset(m, 0, sizeof(LLSModel));
+    m->indep_count = indep_count;
+    m->update_lls = update_lls;
+    m->evaluate_lls = evaluate_lls;
+    if (ARCH_X86)
+        ff_init_lls_x86(m);
 }
-
-#endif