]> git.sesse.net Git - ffmpeg/blobdiff - libavutil/lls.c
avframe: add AV_FRAME_DATA_MATRIXENCODING side data type.
[ffmpeg] / libavutil / lls.c
index 645e52874450119b157140e155afa4f437554660..f87c2cd153302a608639970a377e8e5eabb055ad 100644 (file)
 #include <math.h>
 #include <string.h>
 
+#include "attributes.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];
         }
     }
 }
 
-void avpriv_solve_lls(LLSModel *m, double threshold, int min_order)
+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 +100,7 @@ void avpriv_solve_lls(LLSModel *m, double threshold, int 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,24 +111,34 @@ 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)
+av_cold void avpriv_init_lls(LLSModel *m, int indep_count)
 {
-    return avpriv_init_lls(m, indep_count);
+    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);
+}
+
+#if FF_API_LLS_PRIVATE
+av_cold void av_init_lls(LLSModel *m, int indep_count)
+{
+    avpriv_init_lls(m, indep_count);
 }
 void av_update_lls(LLSModel *m, double *param, double decay)
 {
-    return avpriv_update_lls(m, param, decay);
+    m->update_lls(m, param);
 }
 void av_solve_lls(LLSModel *m, double threshold, int min_order)
 {
-    return avpriv_solve_lls(m, threshold, min_order);
+    avpriv_solve_lls(m, threshold, min_order);
 }
 double av_evaluate_lls(LLSModel *m, double *param, int order)
 {
-    return avpriv_evaluate_lls(m, param, order);
+    return m->evaluate_lls(m, param, order);
 }
-#endif
+#endif /* FF_API_LLS_PRIVATE */
 
 #ifdef TEST
 
@@ -151,17 +156,17 @@ int main(void)
     avpriv_init_lls(&m, 3);
 
     for (i = 0; i < 100; i++) {
-        double var[4];
+        LOCAL_ALIGNED(32, 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);
+        m.update_lls(&m, var);
         avpriv_solve_lls(&m, 0.001, 0);
         for (order = 0; order < 3; order++) {
-            eval = avpriv_evaluate_lls(&m, var + 1, order);
+            eval = m.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],