- publishing free software manuals
GNU Scientific Library Reference Manual - Third Edition (v1.12)
by M. Galassi, J. Davies, J. Theiler, B. Gough, G. Jungman, P. Alken, M. Booth, F. Rossi
Paperback (6"x9"), 592 pages, 60 figures
ISBN 0954612078
RRP £24.95 ($39.95)

Get a printed copy>>>

8.3.2 Accessing vector elements

Unlike fortran compilers, C compilers do not usually provide support for range checking of vectors and matrices.(6) The functions gsl_vector_get and gsl_vector_set can perform portable range checking for you and report an error if you attempt to access elements outside the allowed range.

The functions for accessing the elements of a vector or matrix are defined in ‘gsl_vector.h’ and declared extern inline to eliminate function-call overhead. You must compile your program with the preprocessor macro HAVE_INLINE defined to use these functions.

If necessary you can turn off range checking completely without modifying any source files by recompiling your program with the preprocessor definition GSL_RANGE_CHECK_OFF. Provided your compiler supports inline functions the effect of turning off range checking is to replace calls to gsl_vector_get(v,i) by v->data[i*v->stride] and calls to gsl_vector_set(v,i,x) by v->data[i*v->stride]=x. Thus there should be no performance penalty for using the range checking functions when range checking is turned off.

If you use a C99 compiler which requires inline functions in header files to be declared inline instead of extern inline, define the macro GSL_C99_INLINE (see 2.5). With GCC this is selected automatically when compiling in C99 mode (-std=c99).

If inline functions are not used, calls to the functions gsl_vector_get and gsl_vector_set will link to the compiled versions of these functions in the library itself. The range checking in these functions is controlled by the global integer variable gsl_check_range. It is enabled by default--to disable it, set gsl_check_range to zero. Due to function-call overhead, there is less benefit in disabling range checking here than for inline functions.

Function: double gsl_vector_get (const gsl_vector * v, size_t i)
This function returns the i-th element of a vector v. If i lies outside the allowed range of 0 to n-1 then the error handler is invoked and 0 is returned.
Function: void gsl_vector_set (gsl_vector * v, size_t i, double x)
This function sets the value of the i-th element of a vector v to x. If i lies outside the allowed range of 0 to n-1 then the error handler is invoked.
Function: double * gsl_vector_ptr (gsl_vector * v, size_t i)
Function: const double * gsl_vector_const_ptr (const gsl_vector * v, size_t i)
These functions return a pointer to the i-th element of a vector v. If i lies outside the allowed range of 0 to n-1 then the error handler is invoked and a null pointer is returned.
ISBN 0954612078GNU Scientific Library Reference Manual - Third Edition (v1.12)See the print edition