Download Lib Lib - Fraunhofer SCAI
Transcript
16 C Language Bindings The arrays are directly used by the vector data type, i.e. changing the content of the arrays also changes the content of the vector. This gives the possibility to efficiently access the vector coefficients as it is shown in the following example: unsigned int n = 1024; double * arr = (double *) malloc( sizeof(double) * n ); vector_t x = hlib_vector_import_array( arr, n, & info ); for ( i = 0; i < n; i++ ) arr[i] = i+1; The coefficient i of the vector x would also equal i + 1 as does the array element arr[i+1]. pro Such kind of vectors, e.g. scalar vectors, can also be created directly by H-Lib : Syntax vector_t hlib_vector_alloc_scalar ( unsigned int size, int * info ); vector_t hlib_vector_alloc_cscalar ( unsigned int size, int * info ); Arguments size Size of the scalar vector. Since no external C array is available to access the elements of the vectors, this is accompro plished by H-Lib functions. To get a specific element of a vector, the following two functions can be used: Syntax double hlib_vector_entry_get ( const vector_t unsigned int int * complex_t hlib_vector_centry_get ( const vector_t unsigned int int * Arguments x Vector to get element from. i Position of the element in the vector. Similarly, the setting of a vector element is defined: x, i, info ); x, i, info );