help-gsl
[Top][All Lists]
Advanced

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

[Help-gsl] Vector and matrix views


From: Dimitris Papavasiliou
Subject: [Help-gsl] Vector and matrix views
Date: Thu, 08 Dec 2005 02:17:26 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.8) Gecko/20050513 Debian/1.7.8-1

Hi all,

I need to quickly and efficiently create a gsl vector/matrix from a C array but doing something like

+====
gsl_vector_view v_view;
gsl_vector *v;

v_view = gsl_vector_view_from_array(array, n);
v = &v_view.vector;
+====

tends to get tedious and bloat functions where many vectors are manipulated. Also using &v_view.vector to refer to the vector is ugly and makes to code less readable.

Would something like this work

+====
gsl_vector v;  /* a struct, not a pointer */

v = gsl_vector_view_from_array(array, n).vector;
+====

I know this looks ugly too but hidden behind a macro it would be ok. Would this work correctly? I've tried it and it seems to work but I'd like to make sure. If it works then maybe it would be useful as a macro in GSL itself

#define gsl_vector_from_array(array, n) gsl_vector_view_from_array((array), (n)).vector

and similarly for const, matrices, etc.

On a side note: why do views have a separate struct with only one member? I've read in an old message in the archive that this is so in order to make const vectors work but I can't imagine how keeping a struct with one member is any different than keeping the member itself. If it is't too much trouble could someone please explain?

I'm asking because, if you use the GSL to do calculations with matrices/vectors which need to be stored in C arrays (so that they can be passed to opengl for example) keeping an extra struct for each vector/matrix can be anoying in complex computations. In fact this is what kept me from using the GSL when I first discovered it half a year ago. Let me say though, after all that whining that I was otherwise thrilled with it as this is a pretty amazing library design-wise and even used its ODE solvers with no problems in a cloth simulation.

Dimitris P.




reply via email to

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