【问题标题】:What is the "const gsl_vector_float" required by GSL BLAS functions?GSL BLAS 函数所需的“const gsl_vector_float”是什么?
【发布时间】:2016-11-28 16:23:46
【问题描述】:

我正在尝试使用 GSL 来计算两个向量之间的点积。向量是矩阵列的视图。我将函数称为gsl_blas_dsdot( &view1.vector, &view2.vector, &val),但在编译时我收到警告,指出函数预期参数类型const gsl_vector_float *,我得到一个无意义的结果。下面是一段代码来演示:

#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
}

我使用 gcc 版本 5.4.0、GSL 版本 2.2.1 进行编译,具有以下内容:

gcc example.c -o example -lgsl -lgslcblas

我收到以下警告,虽然程序执行,但结果是荒谬的:

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 * 

另请注意,使用 get_matrix_get_col() 将矩阵列复制到 gsl_vector 类型会导致相同的警告。

有人可以帮忙吗?这些 gsl 向量和向量视图是什么使它们成为不兼容的类型?这些const gsl_vector_float 类型是什么?

【问题讨论】:

    标签: c gcc blas gsl


    【解决方案1】:

    我仍然不知道const gsl_vector_float 是什么,但我确实发现使用函数gsl_blas_ddot 而不是gsl_blas_dsdot 可以在没有警告的情况下编译并正确执行。

    According to the documentation,我希望提供更多细节,gsl_blas_ddotconst gsl_vector * 作为参数。这显然与有问题的const gsl_vector_float * 不同。

    【讨论】:

    • 有点晚了,不过,你可以把gsl_vector当作gsl_vector_double(因为默认类型是double),那么gsl_vector_double和gsl_vector_float的区别就清楚了。附:你可以接受你自己的答案是正确的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-26
    • 1970-01-01
    • 1970-01-01
    • 2010-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多