X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fcovariance-matrix.c;h=c419ce02e8b2357a868526aff9147f172b1125d7;hb=9e8cf8a1587fa439394b7b2bb6f707bb26c6955e;hp=e1b612affe747949867ea53efadfb4de64b1c5a5;hpb=468d19460a8bc3fc9541cde13db5d88e02da71f2;p=pspp-builds.git diff --git a/src/math/covariance-matrix.c b/src/math/covariance-matrix.c index e1b612af..c419ce02 100644 --- a/src/math/covariance-matrix.c +++ b/src/math/covariance-matrix.c @@ -71,7 +71,7 @@ struct covariance_matrix -static struct hsh_table *covariance_hsh_create (size_t); +static struct hsh_table *covariance_hsh_create (size_t *); static hsh_hash_func covariance_accumulator_hash; static unsigned int hash_numeric_alpha (const struct variable *, const struct variable *, @@ -114,7 +114,8 @@ covariance_matrix_init (size_t n_variables, result = xmalloc (sizeof (*result)); result->cov = NULL; - result->ca = covariance_hsh_create (n_variables); + result->n_variables = n_variables; + result->ca = covariance_hsh_create (&result->n_variables); result->m = NULL; result->m1 = NULL; result->missing_handling = missing_handling; @@ -140,7 +141,7 @@ covariance_matrix_init (size_t n_variables, } } result->v_variables = v_variables; - result->n_variables = n_variables; + result->n_pass = n_pass; return result; @@ -349,15 +350,10 @@ covariance_accumulator_hash (const void *h, const void *aux) } if (var_is_alpha (v_max) && var_is_alpha (v_min)) { - unsigned int tmp; - char *x = - xnmalloc (1 + var_get_width (v_max) + var_get_width (v_min), - sizeof (*x)); - strncpy (x, val_max->s, var_get_width (v_max)); - strncat (x, val_min->s, var_get_width (v_min)); - tmp = *n_vars * (*n_vars + 1 + idx_max) + idx_min + hsh_hash_string (x); - free (x); - return tmp; + 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; } return -1u; } @@ -369,11 +365,11 @@ covariance_accumulator_hash (const void *h, const void *aux) in the data. */ static struct hsh_table * -covariance_hsh_create (size_t n_vars) +covariance_hsh_create (size_t *n_vars) { - return hsh_create (n_vars * n_vars, covariance_accumulator_compare, + return hsh_create (*n_vars * *n_vars, covariance_accumulator_compare, covariance_accumulator_hash, covariance_accumulator_free, - &n_vars); + n_vars); } static void @@ -555,6 +551,7 @@ update_hash_entry (struct hsh_table *c, ca->sum2 = update_sum (ca->v2, ca->val2, iv_f2); ca->ssize = 1.0; new_entry = hsh_insert (c, ca); + if (new_entry != NULL) { new_entry->dot_product += ca->dot_product; @@ -777,6 +774,7 @@ covariance_matrix_insert (struct design_matrix *cov, covariance_matrix_insert (cov, v2, v1, val2, val1, product); } } + gsl_matrix_set (cov->m, row, col, product); }