const struct variable **vars = mr->cvars;
size_t n_vars = mr->n_cvars;
- *mm = (struct matrix_material) {
- .n = gsl_matrix_calloc (n_vars, n_vars),
- .mean_matrix = gsl_matrix_calloc (n_vars, n_vars),
- .var_matrix = gsl_matrix_calloc (n_vars, n_vars),
- };
+ *mm = (struct matrix_material) { .n = NULL };
struct matrix
{
{
struct substring rowtype = matrix_reader_get_string (c, mr->rowtype);
- gsl_matrix *v
- = (ss_equals_case (rowtype, ss_cstr ("N")) ? mm->n
- : ss_equals_case (rowtype, ss_cstr ("MEAN")) ? mm->mean_matrix
- : ss_equals_case (rowtype, ss_cstr ("STDDEV")) ? mm->var_matrix
+ gsl_matrix **v
+ = (ss_equals_case (rowtype, ss_cstr ("N")) ? &mm->n
+ : ss_equals_case (rowtype, ss_cstr ("MEAN")) ? &mm->mean_matrix
+ : ss_equals_case (rowtype, ss_cstr ("STDDEV")) ? &mm->var_matrix
: NULL);
if (v)
{
+ if (!*v)
+ *v = gsl_matrix_calloc (n_vars, n_vars);
+
for (int x = 0; x < n_vars; ++x)
{
double n = case_num (c, vars[x]);
- if (v == mm->var_matrix)
+ if (v == &mm->var_matrix)
n *= n;
for (int y = 0; y < n_vars; ++y)
- gsl_matrix_set (v, y, x, n);
+ gsl_matrix_set (*v, y, x, n);
}
continue;
}