From: Jason H Stover Date: Fri, 5 Sep 2008 20:37:18 +0000 (-0400) Subject: Added design_matrix_clone() to clone a design matrix. X-Git-Tag: v0.7.1~50^2~73 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ef859a7962e2d98b192844b07f39017df11681b;p=pspp-builds.git Added design_matrix_clone() to clone a design matrix. --- diff --git a/src/math/design-matrix.c b/src/math/design-matrix.c index 298d0335..e991d2a3 100644 --- a/src/math/design-matrix.c +++ b/src/math/design-matrix.c @@ -191,3 +191,25 @@ design_matrix_set_numeric (struct design_matrix *dm, size_t row, assert (col != DM_COLUMN_NOT_FOUND); gsl_matrix_set (dm->m, row, col, val->f); } + +struct design_matrix * +design_matrix_clone (const struct design_matrix *dm) +{ + struct design_matrix *result; + size_t i; + size_t j; + + assert (dm != NULL); + result = xmalloc (sizeof *result); + result->vars = xnmalloc (dm->n_vars, sizeof *dm->vars); + result->n_vars = dm->n_vars; + result->m = gsl_matrix_alloc (dm->m->size1, dm->m->size2); + + gsl_matrix_memcpy (result->m, dm->m); + for (i = 0; i < result->n_vars; i++) + { + result->vars[i] = dm->vars[i]; + } + return result; +} +