I am using GNU scientific library, and I want to initialize a matrix with values, but I can't understand how to do without a loop :
This works :
gsl_matrix * m = gsl_matrix_alloc (3, 3);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
gsl_matrix_set (m, i, j, 100*i + j);
But I would like to do something like that :
double data[] = { i , 1/2.0, 1/3.0,
1/2.0, 1/3.0, 1/4.0,
1/3.0, 1/4.0, 1/5.0};
gsl_matrix mat = gsl_matrix_from_array(data); // does not exists
Is there a way to do that ?
You could use
std::copy()
to do this.