Hi Matt,
#Declare with
gsl_vector *vectors;
gsl_vector *area;
#Then when you know their size
vectors = gsl_vector_alloc(size_v);
area = gsl_vector_alloc(size_a);
gsl_vector element precision is double by default. Some posts lately
have addressed the virtues of adapting for float precision when double
is unnecessary. Also you may also want to look into analogous
gsl_matrix structures. There certainly are cases where you want to
have a express a conceptual matrix as a mathematical vector, but if
you're doing linear algebra on your *vectors at all, look into the
gsl_matrix.
Cheers,
john
On 25/08/2007, at 9:07 PM, Matthew Boulton wrote:
Hello. I'm wondering what is the best way to declare a GSL vector or
matrix contained within a structure?
For example, at present I have a structure defined as follows:
typedef struct
{
int x,y;
DATA_TYPE **vectors;
DATA_TYPE *area;
double **mat;
double *scprod;
double sum;
double chi2;
double norm;
double diff;
char keep;
} stamp_struct;
stamp_struct *stamps;
where DATA_TYPE defines a double precision variable. Now currently
the code allocates memory using malloc for the vectors and matrices.
For example:
for( i = 0 ; i < stamp_number ; i++ )
{
for( j = 0 ; j < ncomp_kernel + nbg_vectors ; j++ )
{
stamps[i].vectors = (DATA_TYPE **)malloc( ( ncomp_kernel +
nbg_vectors ) * sizeof(DATA_TYPE *) );
stamps[i].vectors[j] = (DATA_TYPE *)malloc( stamp_size *
stamp_size * sizeof(DATA_TYPE) );
}
}
I'm assuming the structure declaration "DATA_TYPE **vectors;" can be
replaced with "gsl_matrix *vectors". However I'm not sure how I can
replace the above code. Usually I would have something like the
following:
gsl_matrix *stamps.vectors = gsl_matrix_calloc( ncomp_kernel +
nbg_vectors , stamp_size * stamp_size );
but this doesn't look right. Because it is a structure do I declare
each bit before and after the . as a separate GSL vector? Sorry if
this seems like an obvious question!
Kind Regards,
Matt
_______________________________________________
Help-gsl mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-gsl
---------------------------------------------------------
Dr John Gehman (address@hidden)
Research Fellow; Separovic Lab
School of Chemistry
University of Melbourne (Australia)