X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Flinreg%2Fcoefficient.c;h=c98c9abcc49d8713e8c83e7615cb01aff47be3fc;hb=7ae8b9ba0e2634a5b72ac6470ebbdf92a78b7892;hp=d1fcbfa2e4bb6a145d0404c9d5493c7c397a62a8;hpb=2417f6ed8121e775b6ca96821ce79e862958e20d;p=pspp diff --git a/src/math/linreg/coefficient.c b/src/math/linreg/coefficient.c index d1fcbfa2e4..c98c9abcc4 100644 --- a/src/math/linreg/coefficient.c +++ b/src/math/linreg/coefficient.c @@ -44,6 +44,7 @@ struct varinfo void pspp_linreg_coeff_free (struct pspp_linreg_coeff *c) { + free (c->v_info); free (c); } @@ -60,15 +61,18 @@ pspp_linreg_coeff_init (pspp_linreg_cache * c, struct design_matrix *X) struct pspp_linreg_coeff *coeff; c->coeff = xnmalloc (X->m->size2 + 1, sizeof (*c->coeff)); + c->coeff[0] = xmalloc (sizeof (*c->coeff[0])); + c->coeff[0]->v_info = NULL; /* Intercept has no associated variable. */ for (i = 0; i < X->m->size2; i++) { j = i + 1; /* The first coefficient is the intercept. */ - coeff = c->coeff + j; + c->coeff[j] = xmalloc (sizeof (*c->coeff[j])); + coeff = c->coeff[j]; coeff->n_vars = n_vals; /* Currently, no procedures allow interactions. This line will have to change when procedures that allow interaction terms are written. - */ + */ coeff->v_info = xnmalloc (coeff->n_vars, sizeof (*coeff->v_info)); assert (coeff->v_info != NULL); coeff->v_info->v = @@ -137,7 +141,8 @@ pspp_linreg_coeff_get_n_vars (struct pspp_linreg_coeff *c) } /* - Which variable does this coefficient match? + Which variable does this coefficient match? I should be + 0 unless the coefficient refers to an interaction term. */ const struct variable * pspp_linreg_coeff_get_var (struct pspp_linreg_coeff *c, int i) @@ -201,11 +206,11 @@ pspp_linreg_get_coeff (const pspp_linreg_cache * c, return NULL; } - result = c->coeff + i; + result = c->coeff[i]; tmp = pspp_linreg_coeff_get_var (result, 0); while (tmp->index != v->index && i < c->n_coeffs) { - result = c->coeff + i; + result = c->coeff[i]; tmp = pspp_linreg_coeff_get_var (result, 0); i++; } @@ -228,7 +233,7 @@ pspp_linreg_get_coeff (const pspp_linreg_cache * c, val, v->width)) { /* FIX THIS */ i++; - result = c->coeff + i; + result = c->coeff[i]; tmp = pspp_linreg_coeff_get_var (result, 0); } if (i == c->n_coeffs)