X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fdesign-matrix.c;h=8f125c58b1e734d3b5d38ce1262e1e4477280edd;hb=d6111d26da0701438a2e2813f14b0edfdf5453c8;hp=e3743228e6ab30e1bcf9117e9de14cb8b6720c3b;hpb=18918bb7713dd3f7d0b0815d8372e8d454e2f2dc;p=pspp-builds.git diff --git a/src/math/design-matrix.c b/src/math/design-matrix.c index e3743228..8f125c58 100644 --- a/src/math/design-matrix.c +++ b/src/math/design-matrix.c @@ -247,8 +247,8 @@ design_matrix_set_case_count (struct design_matrix *dm, const struct variable *v /* Get the number of cases for V. */ -void -design_matrix_get_case_count (struct design_matrix *dm, const struct variable *v) +size_t +design_matrix_get_case_count (const struct design_matrix *dm, const struct variable *v) { size_t i; assert (dm != NULL); @@ -258,4 +258,50 @@ design_matrix_get_case_count (struct design_matrix *dm, const struct variable *v return dm->n_cases[i]; } - +size_t +design_matrix_get_n_cols (const struct design_matrix *d) +{ + return d->m->size2; +} + +size_t +design_matrix_get_n_rows (const struct design_matrix *d) +{ + return d->m->size1; +} + +double +design_matrix_get_element (const struct design_matrix *d, size_t row, size_t col) +{ + return (gsl_matrix_get (d->m, row, col)); +} + +void +design_matrix_set_element (const struct design_matrix *d, size_t row, size_t col, double x) +{ + gsl_matrix_set (d->m, row, col, x); +} + +/* + Return the subscript of the column of the design matrix + corresponding to VAL. If VAR is categorical with d categories, its + first category should correspond to the origin in d-dimensional + Euclidean space, so there is no subscript for this value. + */ +size_t +dm_get_exact_subscript (const struct design_matrix *dm, const struct variable *var, + const union value *val) +{ + size_t result; + + result = design_matrix_var_to_column (dm, var); + if (var_is_alpha (var)) + { + if (cat_is_origin (var, val)) + { + return -1u; + } + result += cat_value_find (var, val) - 1; + } + return result; +}