Added design_matrix_clone() to clone a design matrix.
authorJason H Stover <jhs@math.gcsu.edu>
Fri, 5 Sep 2008 20:37:18 +0000 (16:37 -0400)
committerJason H Stover <jhs@math.gcsu.edu>
Fri, 5 Sep 2008 20:37:18 +0000 (16:37 -0400)
src/math/design-matrix.c

index 298d03357b7208e66392c0b15bec0eb9e0f0146b..e991d2a398b007acd2c51d66cf49b6664872eb95 100644 (file)
@@ -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;
+}
+