Remove useless code
[pspp-builds.git] / src / math / covariance.c
index 5dc1782638aff4f294253fd20d87c4e6b2e4c426..8e9f1db14bda67435e316049507196e476bae302 100644 (file)
@@ -25,6 +25,7 @@
 #include "libpspp/assertion.h"
 #include "libpspp/misc.h"
 #include "math/categoricals.h"
+#include "math/interaction.h"
 #include "math/moments.h"
 
 #include "gl/xalloc.h"
@@ -159,8 +160,8 @@ covariance_1pass_create (size_t n_vars, const struct variable *const *vars,
 
   cov->n_cm = (n_vars * (n_vars - 1)  ) / 2;
 
-  if (cov->n_cm > 0)
-    cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm);
+
+  cov->cm = xcalloc (cov->n_cm, sizeof *cov->cm);
   cov->categoricals = NULL;
 
   return cov;
@@ -247,7 +248,7 @@ is_missing (const struct covariance *cov, int i, const struct ccase *c)
 {
   const struct variable *var = i < cov->n_vars ?
     cov->vars[i] : 
-    categoricals_get_variable_by_subscript (cov->categoricals, i - cov->n_vars);
+    categoricals_get_interaction_by_subscript (cov->categoricals, i - cov->n_vars)->vars[0];
 
   const union value *val = case_data (c, var);
 
@@ -346,14 +347,16 @@ covariance_accumulate_pass2 (struct covariance *cov, const struct ccase *c)
       assert (cov->state == 1);
       cov->state = 2;
 
+      if (cov->categoricals)
+       categoricals_done (cov->categoricals);
+
       cov->dim = cov->n_vars;
       
       if (cov->categoricals)
-       cov->dim += categoricals_total (cov->categoricals) 
-         - categoricals_get_n_variables (cov->categoricals);
+       cov->dim += categoricals_df_total (cov->categoricals);
 
       cov->n_cm = (cov->dim * (cov->dim - 1)  ) / 2;
-      cov->cm = xcalloc (sizeof *cov->cm, cov->n_cm);
+      cov->cm = xcalloc (cov->n_cm, sizeof *cov->cm);
 
       /* Grow the moment matrices so that they're large enough to accommodate the
         categorical elements */
@@ -362,9 +365,6 @@ covariance_accumulate_pass2 (struct covariance *cov, const struct ccase *c)
          cov->moments[i] = resize_matrix (cov->moments[i], cov->dim);
        }
 
-      if (cov->categoricals)
-       categoricals_done (cov->categoricals);
-
       /* Populate the moments matrices with the categorical value elements */
       for (i = cov->n_vars; i < cov->dim; ++i)
        {
@@ -631,22 +631,6 @@ covariance_calculate (struct covariance *cov)
 static gsl_matrix *
 covariance_calculate_double_pass_unnormalized (struct covariance *cov)
 {
-  size_t i, j;
-  for (i = 0 ; i < cov->dim; ++i)
-    {
-      for (j = 0 ; j < cov->dim; ++j)
-       {
-         int idx;
-         double *x = gsl_matrix_ptr (cov->moments[MOMENT_VARIANCE], i, j);
-
-         idx = cm_idx (cov, i, j);
-         if ( idx >= 0)
-           {
-             x = &cov->cm [idx];
-           }
-       }
-    }
-
   return  cm_to_gsl (cov);
 }