From: Jason H Stover Date: Wed, 29 Apr 2009 21:23:17 +0000 (-0400) Subject: Moved is_origin and get_exact_subscript to design-matrix.[ch] X-Git-Tag: v0.7.3~134 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3bfe739c926ff5729b0f7849d49b79d65a9d0c91;p=pspp-builds.git Moved is_origin and get_exact_subscript to design-matrix.[ch] --- diff --git a/src/math/covariance-matrix.c b/src/math/covariance-matrix.c index 17799cfc..275d7cfe 100644 --- a/src/math/covariance-matrix.c +++ b/src/math/covariance-matrix.c @@ -735,47 +735,6 @@ covariance_matrix_accumulate (struct covariance_matrix *cov, { cov->accumulate (cov, ccase, (const struct interaction_variable **) aux, n_intr); } -/* - If VAR is categorical with d categories, its first category should - correspond to the origin in d-dimensional Euclidean space. - */ -static bool -is_origin (const struct variable *var, const union value *val) -{ - if (var_is_numeric (var)) - { - return false; - } - if (cat_value_find (var, val) == 0) - { - return true; - } - return false; -} - -/* - 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. - */ -static size_t -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 (is_origin (var, val)) - { - return -1u; - } - result += cat_value_find (var, val) - 1; - } - return result; -} /* Return the value corresponding to subscript TARGET. If that value corresponds @@ -796,7 +755,7 @@ get_value_from_subscript (const struct design_matrix *dm, size_t target) for (i = 0; i < cat_get_n_categories (var); i++) { result = cat_subscript_to_value (i, var); - if (get_exact_subscript (dm, var, result) == target) + if (dm_get_exact_subscript (dm, var, result) == target) { return result; } @@ -819,10 +778,10 @@ is_covariance_contributor (const struct covariance_accumulator *ca, const struct { if (var_get_dict_index (v2) == var_get_dict_index (ca->v2)) { - k = get_exact_subscript (dm, v1, ca->val1); + k = dm_get_exact_subscript (dm, v1, ca->val1); if (k == i) { - k = get_exact_subscript (dm, v2, ca->val2); + k = dm_get_exact_subscript (dm, v2, ca->val2); if (k == j) { return true; @@ -834,10 +793,10 @@ is_covariance_contributor (const struct covariance_accumulator *ca, const struct { if (var_get_dict_index (v2) == var_get_dict_index (ca->v1)) { - k = get_exact_subscript (dm, v1, ca->val2); + k = dm_get_exact_subscript (dm, v1, ca->val2); if (k == i) { - k = get_exact_subscript (dm, v2, ca->val1); + k = dm_get_exact_subscript (dm, v2, ca->val1); if (k == j) { return true; diff --git a/src/math/design-matrix.c b/src/math/design-matrix.c index b81859aa..030efd7a 100644 --- a/src/math/design-matrix.c +++ b/src/math/design-matrix.c @@ -281,3 +281,44 @@ design_matrix_set_element (const struct design_matrix *d, size_t row, size_t col { gsl_matrix_set (d->m, row, col, x); } +/* + If VAR is categorical with d categories, its first category should + correspond to the origin in d-dimensional Euclidean space. + */ +static bool +is_origin (const struct variable *var, const union value *val) +{ + if (var_is_numeric (var)) + { + return false; + } + if (cat_value_find (var, val) == 0) + { + return true; + } + return false; +} + +/* + 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 (is_origin (var, val)) + { + return -1u; + } + result += cat_value_find (var, val) - 1; + } + return result; +} diff --git a/src/math/design-matrix.h b/src/math/design-matrix.h index 45814580..b1cda5a9 100644 --- a/src/math/design-matrix.h +++ b/src/math/design-matrix.h @@ -94,4 +94,7 @@ size_t design_matrix_get_n_cols (const struct design_matrix *); size_t design_matrix_get_n_rows (const struct design_matrix *); double design_matrix_get_element (const struct design_matrix *, size_t, size_t); void design_matrix_set_element (const struct design_matrix *, size_t, size_t, double); +size_t dm_get_exact_subscript (const struct design_matrix *, const struct variable *, + const union value *); + #endif