From 207ea79ecdd7500ec0ecaf3d7a79488ba78ca560 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 7 Jul 2011 11:39:21 +0200 Subject: [PATCH] Categoricals: remove var member which is no longer required --- src/math/categoricals.c | 17 ++++------------- src/math/categoricals.h | 1 + src/math/covariance.c | 15 +++++++++++++++ src/math/covariance.h | 2 ++ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/math/categoricals.c b/src/math/categoricals.c index 16bb46f6..58015c90 100644 --- a/src/math/categoricals.c +++ b/src/math/categoricals.c @@ -48,7 +48,6 @@ struct var_params /* A map indexed by a union values */ struct hmap map; - const struct variable *var; const struct interaction *iact; int base_subscript_short; @@ -82,7 +81,6 @@ struct categoricals /* The weight variable */ const struct variable *wv; - /* An array of var_params */ struct var_params *vp; @@ -244,7 +242,6 @@ categoricals_create (const struct interaction **inter, size_t n_inter, for (i = 0 ; i < cat->n_vp; ++i) { hmap_init (&cat->vp[i].map); - cat->vp[i].var = inter[i]->vars[0]; cat->vp[i].iact = inter[i]; } @@ -266,23 +263,17 @@ categoricals_update (struct categoricals *cat, const struct ccase *c) for (i = 0 ; i < cat->n_vp; ++i) { const struct interaction *iact = cat->vp[i].iact; - const struct variable *var = cat->vp[i].var; - - const union value *val = case_data (c, var); size_t hash; struct value_node *node ; -#if XXX - if ( var_is_value_missing (var, val, cat->exclude)) + if ( interaction_case_is_missing (iact, c, cat->exclude)) continue; -#endif hash = interaction_case_hash (iact, c); node = lookup_case (&cat->vp[i].map, iact, c); if ( NULL == node) { - int width = var_get_width (var); node = pool_malloc (cat->pool, sizeof *node); node->ccase = case_ref (c); @@ -304,7 +295,7 @@ categoricals_update (struct categoricals *cat, const struct ccase *c) cat->vp[i].cc += weight; if (cat->update) - cat->update (node->user_data, cat->exclude, cat->wv, var, c, cat->aux1, cat->aux2); + cat->update (node->user_data, cat->exclude, cat->wv, NULL, c, cat->aux1, cat->aux2); } } @@ -409,11 +400,11 @@ categoricals_get_variable_by_subscript (const struct categoricals *cat, int subs { int index = reverse_variable_lookup_short (cat, subscript); - return cat->vp[index].var; + return cat->vp[index].iact->vars[0]; } /* Return the interaction corresponding to SUBSCRIPT */ -static const struct interaction * +const struct interaction * categoricals_get_interaction_by_subscript (const struct categoricals *cat, int subscript) { int index = reverse_variable_lookup_short (cat, subscript); diff --git a/src/math/categoricals.h b/src/math/categoricals.h index 2cd55b5e..1a698dea 100644 --- a/src/math/categoricals.h +++ b/src/math/categoricals.h @@ -79,6 +79,7 @@ void categoricals_done (const struct categoricals *cat); const struct variable * categoricals_get_variable_by_subscript (const struct categoricals *cat, int subscript); double categoricals_get_weight_by_subscript (const struct categoricals *cat, int subscript); +const struct interaction *categoricals_get_interaction_by_subscript (const struct categoricals *cat, int subscript); double categoricals_get_sum_by_subscript (const struct categoricals *cat, int subscript); diff --git a/src/math/covariance.c b/src/math/covariance.c index adad3439..aed42436 100644 --- a/src/math/covariance.c +++ b/src/math/covariance.c @@ -756,3 +756,18 @@ covariance_get_var_indices (const struct covariance *cov, const struct variable vars[i] = categoricals_get_variable_by_subscript (cov->categoricals, i - cov->n_vars); } } + + +void +covariance_get_interaction_indices (const struct covariance *cov, const struct interaction **iacts) +{ + int i; + for (i = 0; i < cov->n_vars; i++) + { + iacts[i] = cov->vars[i]; + } + for (i = cov->n_vars; i < cov->dim; i++) + { + iacts[i] = categoricals_get_interaction_by_subscript (cov->categoricals, i - cov->n_vars); + } +} diff --git a/src/math/covariance.h b/src/math/covariance.h index 0231f798..87afd8b2 100644 --- a/src/math/covariance.h +++ b/src/math/covariance.h @@ -47,6 +47,8 @@ void covariance_destroy (struct covariance *cov); const gsl_matrix *covariance_moments (const struct covariance *cov, int m); const struct categoricals * covariance_get_categoricals (const struct covariance *cov); +struct interaction; +void covariance_get_interaction_indices (const struct covariance *cov, const struct interaction **iacts); void covariance_get_var_indices (const struct covariance *cov, const struct variable **vars); size_t covariance_dim (const struct covariance * cov); -- 2.30.2