X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fcovariance-matrix.c;h=2e83749c6ed27155235dac0f4bb37e9d98e212ea;hb=ec98753885c4b9e38978d61262a9aa4ef4f8a69a;hp=bb17d99aa9c616d49aa1f7d3f3f62201d3508710;hpb=4fcc4128123c6f7b80d40adbeea58ae56b9be55c;p=pspp-builds.git diff --git a/src/math/covariance-matrix.c b/src/math/covariance-matrix.c index bb17d99a..2e83749c 100644 --- a/src/math/covariance-matrix.c +++ b/src/math/covariance-matrix.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -148,7 +148,25 @@ covariance_matrix_init (size_t n_variables, return result; } - +static size_t +get_n_rows (size_t n_variables, size_t *v_variables[]) +{ + size_t i; + size_t result = 0; + for (i = 0; i < n_variables; i++) + { + if (var_is_numeric (v_variables[i])) + { + result++; + } + else if (var_is_alpha (v_variables[i])) + { + size_t n_categories = cat_get_n_categories (v_variables[i]); + result += n_categories - 1; + } + } + return result; +} /* The covariances are stored in a DESIGN_MATRIX structure. */ @@ -156,8 +174,8 @@ struct design_matrix * covariance_matrix_create (size_t n_variables, const struct variable *v_variables[]) { - return design_matrix_create (n_variables, v_variables, - (size_t) n_variables); + size_t n_rows = get_n_rows (n_variables, v_variables); + return design_matrix_create (n_variables, v_variables, n_rows); } static void @@ -354,10 +372,9 @@ covariance_accumulator_hash (const void *h, const void *aux) } if (var_is_alpha (v_max) && var_is_alpha (v_min)) { - unsigned tmp = hsh_hash_bytes (val_max, var_get_width (v_max)); - tmp ^= hsh_hash_bytes (val_min, var_get_width (v_min)); - tmp += *n_vars * (*n_vars + 1 + idx_max) + idx_min; - return (size_t) tmp; + unsigned hash = hash_bytes (val_max, var_get_width (v_max), 0); + hash = hash_bytes (val_min, var_get_width (v_min), hash); + return hash_int (*n_vars * (*n_vars + 1 + idx_max) + idx_min, hash); } return -1u; } @@ -460,7 +477,7 @@ hash_numeric_alpha (const struct variable *v1, const struct variable *v2, if (var_is_numeric (v1) && var_is_alpha (v2)) { result = n_vars * ((n_vars + 1) + var_get_dict_index (v1)) - + var_get_dict_index (v2) + hsh_hash_string (val->s); + + var_get_dict_index (v2) + hash_string (val->s, 0); } else if (var_is_alpha (v1) && var_is_numeric (v2)) {