X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fdesign-matrix.c;h=0f5242d5d138a1e85ed7c022c732777d80fb286b;hb=9f472ebb86d3a1b4903bdde1c1371add0b70669a;hp=8678f56ca9fa959f9f3acef1d42f97f57eba3974;hpb=97d4f38945476834fd7fce612b663f19f2b291f8;p=pspp-builds.git diff --git a/src/math/design-matrix.c b/src/math/design-matrix.c index 8678f56c..0f5242d5 100644 --- a/src/math/design-matrix.c +++ b/src/math/design-matrix.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -115,17 +116,17 @@ design_matrix_create (int n_variables, (dm->vars + i)->v = v; /* Allows us to look up the variable from the design matrix. */ (dm->vars + i)->first_column = n_cols; - if (v->type == NUMERIC) + if (var_is_numeric (v)) { (dm->vars + i)->last_column = n_cols; n_cols++; } - else if (v->type == ALPHA) + else if (var_is_alpha (v)) { - assert (v->obs_vals != NULL); + struct cat_vals *obs_vals = var_get_obs_vals (v); (dm->vars + i)->last_column = - (dm->vars + i)->first_column + v->obs_vals->n_categories - 2; - n_cols += v->obs_vals->n_categories - 1; + (dm->vars + i)->first_column + obs_vals->n_categories - 2; + n_cols += obs_vals->n_categories - 1; } } dm->m = gsl_matrix_calloc (n_data, n_cols); @@ -146,8 +147,8 @@ design_matrix_destroy (struct design_matrix *dm) Return the index of the variable for the given column. */ -static size_t -design_matrix_col_to_var_index (const struct design_matrix *dm, size_t col) +struct variable * +design_matrix_col_to_var (const struct design_matrix *dm, size_t col) { size_t i; struct design_matrix_var v; @@ -156,42 +157,11 @@ design_matrix_col_to_var_index (const struct design_matrix *dm, size_t col) { v = dm->vars[i]; if (v.first_column <= col && col <= v.last_column) - return (v.v)->index; - } - return DM_INDEX_NOT_FOUND; -} - -/* - Return a pointer to the variable whose values - are stored in column col. - */ -struct variable * -design_matrix_col_to_var (const struct design_matrix *dm, size_t col) -{ - size_t index; - size_t i; - struct design_matrix_var dmv; - - index = design_matrix_col_to_var_index (dm, col); - for (i = 0; i < dm->n_vars; i++) - { - dmv = dm->vars[i]; - if ((dmv.v)->index == index) - { - return (struct variable *) dmv.v; - } + return (struct variable *) v.v; } return NULL; } -static size_t -cmp_dm_var_index (const struct design_matrix_var *dmv, size_t index) -{ - if (dmv->v->index == index) - return 1; - return 0; -} - /* Return the number of the first column which holds the values for variable v. @@ -206,7 +176,7 @@ design_matrix_var_to_column (const struct design_matrix * dm, for (i = 0; i < dm->n_vars; i++) { tmp = dm->vars[i]; - if (cmp_dm_var_index (&tmp, v->index)) + if (tmp.v == v) { return tmp.first_column; } @@ -225,7 +195,7 @@ dm_var_to_last_column (const struct design_matrix *dm, for (i = 0; i < dm->n_vars; i++) { tmp = dm->vars[i]; - if (cmp_dm_var_index (&tmp, v->index)) + if (tmp.v == v) { return tmp.last_column; } @@ -250,7 +220,7 @@ design_matrix_set_categorical (struct design_matrix *dm, size_t row, size_t lc; double entry; - assert (var->type == ALPHA); + assert (var_is_alpha (var)); fc = design_matrix_var_to_column (dm, var); lc = dm_var_to_last_column (dm, var); assert (lc != DM_COLUMN_NOT_FOUND); @@ -268,7 +238,7 @@ design_matrix_set_numeric (struct design_matrix *dm, size_t row, { size_t col; - assert (var->type == NUMERIC); + assert (var_is_numeric (var)); col = design_matrix_var_to_column ((const struct design_matrix *) dm, var); assert (col != DM_COLUMN_NOT_FOUND); gsl_matrix_set (dm->m, row, col, val->f);