[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] Declaring GSL Matrices and Vectors Within a Structure
From: |
Matthew Boulton |
Subject: |
[Help-gsl] Declaring GSL Matrices and Vectors Within a Structure |
Date: |
Sat, 25 Aug 2007 12:07:50 +0100 |
User-agent: |
Thunderbird 2.0.0.6 (Windows/20070728) |
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] Declaring GSL Matrices and Vectors Within a Structure,
Matthew Boulton <=