This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Naive question from novice C programmer


>What I'm wondering is if there's a way to employ the
GSL
>routines that take arrays as input, where the arrays
are *not*
>defined the GSL way using "gsl_vector_alloc" and so
forth,
>but rather the usual manual way with malloc, i.e.
>xarray = (double *) malloc((nsize)*sizeof(double));

Use the gsl_vector_view facility (section 8.3.5 of the
version 1.0 manual).
for example.....

size_t nsize = 10;
double * x = (double *)
malloc((nsize)*sizeof(double));
if ( x == NULL ) exit(1);
gsl_vector_view xvec = gsl_vector_view_array (x,
nsize);
// use some gsl functions requiring vector
if ( gsl_vector_reverse(&(xvec.vector)) ) exit(1);
if ( gsl_vector_fprintf(stdout, &(xvec.vector), "%f")
) exit(1);

The same type of facility exists for gsl_matrix.  See
the gsl_matrix_view_array() function (section 8.4.5).

marco

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]