help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-gsl] Declaring GSL Matrices and Vectors Within a Structure


From: Matthew Boulton
Subject: Re: [Help-gsl] Declaring GSL Matrices and Vectors Within a Structure
Date: Sun, 26 Aug 2007 21:41:51 +0100
User-agent: Thunderbird 2.0.0.6 (Windows/20070728)

So instead of stamps[i].vectors, I should use say stamps_vectors as a GSL matrix (as I have to take into account the stamps elements and the vectors elements I'm assuming?). I'm basically re-writing someone else's code to use the GSL and it seems to be putting the different elements of stamps[i] to use later in the programme. If I ignore the stamps structure stuff and just use vectors and area as GSL vectors this may cause me problems when each separate value for each stamps[i] element is read.

So my first thought was to convert something like stamps[i].area which would become just a GSL vector called 'area', to a GSL matrix called 'stamps_area'. This gives me back my 2d structure. However, I will be stuck when I come to something like 'stamps.vectors' as vectors will need to be a GSL matrix, so 'stamps_vectors' would need to be some kind of 3D matrix, which I'm not sure is even possible!

I'm happy to implement the above strategy for everything else, but unless I can find an alternative or a 3D matrix function I will be unable to do so for stamps.vectors.

Kind Regards,

Matt


John Gehman wrote:
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)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]