From: Jason H Stover Date: Wed, 1 Apr 2009 20:13:10 +0000 (-0400) Subject: covariance_matrix.c (get_n_rows): New function to compute the number X-Git-Tag: v0.7.3~176^2~8^2 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=80f1c9a909427c7760f39c03f8b6f21b6a5f5a71;p=pspp-builds.git covariance_matrix.c (get_n_rows): New function to compute the number of rows in the covariance matrix. --- diff --git a/src/math/covariance-matrix.c b/src/math/covariance-matrix.c index bb17d99a..95895eae 100644 --- a/src/math/covariance-matrix.c +++ b/src/math/covariance-matrix.c @@ -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