I am trying to use GSL to compute the dot product between two vectors. The vectors are views of the columns of a matrix. I call the function like gsl_blas_dsdot( &view1.vector, &view2.vector, &val)
, but upon compilation I get warnings stating that the function expected argument types const gsl_vector_float *
, and I get a nonsensical result. Here is a code to demonstrate:
#include<stdio.h>
#include<gsl/gsl_matrix.h>
#include<gsl/gsl_vector.h>
#include<gsl/gsl_blas.h>
void main(void){
int i;
double val = 111.111; // Initialize to something
gsl_matrix *A = gsl_matrix_alloc(3,3); //Initialize mx
gsl_matrix_set_identity(A); // Set mx to identity
gsl_matrix_set(A,0,1,3.14);
gsl_vector_view a1 = gsl_matrix_column(A,0); // Vector allocations
gsl_vector_view a2 = gsl_matrix_column(A,1);
/* Print the vectors */
printf("a1 = ");
for(i=0; i<3; i++){
printf("%g ", gsl_vector_get(&a1.vector,i));}
printf("\na2 = ");
for(i=0; i<3; i++){
printf("%g ", gsl_vector_get(&a2.vector,i));}
printf("\n");
gsl_blas_dsdot(&a1.vector, &a2.vector, &val); // Dot product
printf("a1.a2 = %.2f\n", val); // Print result
}
I compile with gcc version 5.4.0, GSL version 2.2.1, with the following:
gcc example.c -o example -lgsl -lgslcblas
And I get the following warnings, and though the program executes, the result is nonsensical:
gsl_dot.c: In function ‘main’:
gsl_dot.c:22:18: warning: passing argument 1 of ‘gsl_blas_dsdot’ from incompatible pointer type [-Wincompatible-pointer-types]
gsl_blas_dsdot(&a1.vector, &a2.vector, &val); // Dot product
^
In file included from gsl_dot.c:4:0:
/usr/local/include/gsl/gsl_blas.h:56:5: note: expected ‘const gsl_vector_float * {aka const struct <anonymous> *}’ but argument is of type ‘gsl_vector * {aka struct <anonymous> *}’
int gsl_blas_dsdot (const gsl_vector_float * X,
^
gsl_dot.c:22:30: warning: passing argument 2 of ‘gsl_blas_dsdot’ from incompatible pointer type [-Wincompatible-pointer-types]
gsl_blas_dsdot(&a1.vector, &a2.vector, &val); // Dot product
^
In file included from gsl_dot.c:4:0:
/usr/local/include/gsl/gsl_blas.h:56:5: note: expected ‘const gsl_vector_float * {aka const struct <anonymous> *}’ but argument is of type ‘gsl_vector * {aka struct <anonymous> *}’
int gsl_blas_dsdot (const gsl_vector_float *
Note also that copying the matrix columns into gsl_vector
types using get_matrix_get_col()
results in the same warnings.
Can anyone please assist? What is it about these gsl vectors and vector views that make them an incompatible type? What are these const gsl_vector_float
types?
I still don't know what a const gsl_vector_float
is, but I did figure out that using the function gsl_blas_ddot
instead of gsl_blas_dsdot
compiles without warnings and executes correctly.
According to the documentation, which I wish gave more detail, gsl_blas_ddot
takes const gsl_vector *
as argument. This is apparently different from the const gsl_vector_float *
in question.