The covariance_calculate() and covariance_calculate_unnormalized()
functions documented that their return values were owned by the covariance
object itself and thus should not be freed by the caller. However, this
documentation was incorrect, because in fact the covariance object did not
retain the pointer at all. This commit fixes the comments, updates
the return values to be non-"const", and changes the callers to free the
returned "gsl_matrix" objects.
{
struct ccase *c;
const gsl_matrix *var_matrix, *samples_matrix, *mean_matrix;
{
struct ccase *c;
const gsl_matrix *var_matrix, *samples_matrix, *mean_matrix;
- const gsl_matrix *cov_matrix;
+ gsl_matrix *cov_matrix;
gsl_matrix *corr_matrix;
struct covariance *cov = covariance_2pass_create (corr->n_vars_total, corr->vars,
NULL,
gsl_matrix *corr_matrix;
struct covariance *cov = covariance_2pass_create (corr->n_vars_total, corr->vars,
NULL,
covariance_destroy (cov);
gsl_matrix_free (corr_matrix);
covariance_destroy (cov);
gsl_matrix_free (corr_matrix);
+ gsl_matrix_free (cov_matrix);
/* Intermediate values used in calculation */
const gsl_matrix *corr ; /* The correlation matrix */
/* Intermediate values used in calculation */
const gsl_matrix *corr ; /* The correlation matrix */
- const gsl_matrix *cov ; /* The covariance matrix */
+ gsl_matrix *cov ; /* The covariance matrix */
const gsl_matrix *n ; /* Matrix of number of samples */
gsl_vector *eval ; /* The eigenvalues */
const gsl_matrix *n ; /* Matrix of number of samples */
gsl_vector *eval ; /* The eigenvalues */
gsl_vector_free (id->msr);
gsl_vector_free (id->eval);
gsl_matrix_free (id->evec);
gsl_vector_free (id->msr);
gsl_vector_free (id->eval);
gsl_matrix_free (id->evec);
+ if (id->cov != NULL)
+ gsl_matrix_free (id->cov);
reg_sweep (cm, 0);
dump_matrix (cm);
reg_sweep (cm, 0);
dump_matrix (cm);
+
+ gsl_matrix_free (cm);
}
if (!taint_has_tainted_successor (taint))
}
if (!taint_has_tainted_successor (taint))
pvw->n_groups = categoricals_total (cats);
pvw->mse = (pvw->sst - pvw->ssa) / (n - pvw->n_groups);
pvw->n_groups = categoricals_total (cats);
pvw->mse = (pvw->sst - pvw->ssa) / (n - pvw->n_groups);
+
+ gsl_matrix_free (cm);
}
for (v = 0; v < cmd->n_vars; ++v)
}
for (v = 0; v < cmd->n_vars; ++v)
size_t dep_subscript;
size_t *rows;
const gsl_matrix *ssizes;
size_t dep_subscript;
size_t *rows;
const gsl_matrix *ssizes;
const gsl_matrix *mean_matrix;
const gsl_matrix *ssize_matrix;
double result = 0.0;
const gsl_matrix *mean_matrix;
const gsl_matrix *ssize_matrix;
double result = 0.0;
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 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
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
-static const gsl_matrix *
covariance_calculate_double_pass (struct covariance *cov)
{
size_t i, j;
covariance_calculate_double_pass (struct covariance *cov)
{
size_t i, j;
return cm_to_gsl (cov);
}
return cm_to_gsl (cov);
}
-static const gsl_matrix *
covariance_calculate_single_pass (struct covariance *cov)
{
size_t i, j;
covariance_calculate_single_pass (struct covariance *cov)
{
size_t i, j;
-/*
- Return a pointer to gsl_matrix containing the pairwise covariances.
- The matrix remains owned by the COV object, and must not be freed.
- Call this function only after all data have been accumulated.
-*/
-const gsl_matrix *
+/* Return a pointer to gsl_matrix containing the pairwise covariances. The
+ caller owns the returned matrix and must free it when it is no longer
+ needed.
+
+ Call this function only after all data have been accumulated. */
+gsl_matrix *
covariance_calculate (struct covariance *cov)
{
if ( cov->state <= 0 )
covariance_calculate (struct covariance *cov)
{
if ( cov->state <= 0 )
/*
Covariance computed without dividing by the sample size.
*/
/*
Covariance computed without dividing by the sample size.
*/
-static const gsl_matrix *
covariance_calculate_double_pass_unnormalized (struct covariance *cov)
{
size_t i, j;
covariance_calculate_double_pass_unnormalized (struct covariance *cov)
{
size_t i, j;
return cm_to_gsl (cov);
}
return cm_to_gsl (cov);
}
-static const gsl_matrix *
covariance_calculate_single_pass_unnormalized (struct covariance *cov)
{
size_t i, j;
covariance_calculate_single_pass_unnormalized (struct covariance *cov)
{
size_t i, j;
-/*
- Return a pointer to gsl_matrix containing the pairwise covariances.
- The matrix remains owned by the COV object, and must not be freed.
- Call this function only after all data have been accumulated.
-*/
-const gsl_matrix *
+/* Return a pointer to gsl_matrix containing the pairwise covariances. The
+ caller owns the returned matrix and must free it when it is no longer
+ needed.
+
+ Call this function only after all data have been accumulated. */
+gsl_matrix *
covariance_calculate_unnormalized (struct covariance *cov)
{
if ( cov->state <= 0 )
covariance_calculate_unnormalized (struct covariance *cov)
{
if ( cov->state <= 0 )
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2009 Free Software Foundation, Inc.
+ Copyright (C) 2009, 2010 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
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
void covariance_accumulate_pass1 (struct covariance *, const struct ccase *);
void covariance_accumulate_pass2 (struct covariance *, const struct ccase *);
void covariance_accumulate_pass1 (struct covariance *, const struct ccase *);
void covariance_accumulate_pass2 (struct covariance *, const struct ccase *);
-const gsl_matrix * covariance_calculate (struct covariance *cov);
-const gsl_matrix * covariance_calculate_unnormalized (struct covariance *);
+gsl_matrix * covariance_calculate (struct covariance *);
+gsl_matrix * covariance_calculate_unnormalized (struct covariance *);
void covariance_destroy (struct covariance *cov);
void covariance_destroy (struct covariance *cov);