help-gsl
[Top][All Lists]
Advanced

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

[Help-gsl] Nature of gsl_vector_view [was "Re: Contents Help-gsl Digest,


From: Rhys Ulerich
Subject: [Help-gsl] Nature of gsl_vector_view [was "Re: Contents Help-gsl Digest, Vol 103, Issue 4 (Vector Views)"]
Date: Mon, 7 May 2012 12:22:04 -0500

Hi Gideon,

First off, it's helpful to have a useful subject rather than sending a
message to the list simply by hitting Reply on a digest.  If you're
unsure how to add details or more questions to your earlier "vector
views" thread, one easy way is to Reply to yourself and CC
address@hidden  That bit of tedium helps to keep the mail archives
cleaner for people who like to search them.

> I remain  a little unclear about what the gsl_vector_view object is.  Right 
> now, I have a code snippet like this:
>
> gsl_vector * y;
>  y = gsl_vector_calloc(2*N);
>  gsl_vector_view  yreal = gsl_vector_subvector(y, 0, N);
>  gsl_vector_view  yimag = gsl_vector_subvector(y, N, N);
>
>
>  for(i = 0; i < p->N; i++){
>
>    b= cexp( _Complex_I * .25 * M_PI * i); // Using complex.h to handle 
> complex numbers
>
>    gsl_vector_set(&yreal.vector, i, creal(b));
>    gsl_vector_set(&yimag.vector, i, cimag(b));
>
>    printf(" y[%i] = %g, y[%i+N] = %g\n", i, gsl_vector_get(y, i),
>           gsl_vector_get(y, i+N));
>
>  }
>
> What's unclear to me is what the gsl_vector_view structure is how
> the structure handles memory.  I see that it encapsulates a gsl_vector object,
> but does that structure just get the necessary pointer information?

If you stare a bit at
http://www.gnu.org/software/gsl/manual/html_node/Vectors.html you'll
see that a gsl_vector, among other things, contains an 'owner' member.
 In your example, y.owner is true so that if you deallocated y, it
would know to deallocate y.block as well.

A gsl_vector_view contains a gsl_vector member named member.  In the
case of your yreal declaration, the line
>  gsl_vector_view  yreal = gsl_vector_subvector(y, 0, N);
simply copies the details from y into a temporary setting owner = 0
along the way.  The compiler copies the temporary into yreal.  Then,
later, when you pass &yreal.vector to gsl_vector_set you're literally
passing a gsl_vector* which does not own y.data but which knows
y.data's value.

If you're not deallocating y in your real code, definitely do so.

Hope that helps,
Rhys



reply via email to

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