gpt4 book ai didi

c - GSL BLAS 函数所需的 "const gsl_vector_float"是什么?

转载 作者:行者123 更新时间:2023-11-30 15:03:05 25 4
gpt4 key购买 nike

我正在尝试使用 GSL 来计算两个 vector 之间的点积。 vector 是矩阵列的 View 。我将该函数称为 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 vector 和 vector View 是什么使它们成为不兼容的类型?这些 const gsl_vector_float 类型是什么?

最佳答案

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

According to the documentation ,我希望提供更多详细信息,gsl_blas_ddot 采用 const gsl_vector * 作为参数。这显然与所讨论的 const gsl_vector_float * 不同。

关于c - GSL BLAS 函数所需的 "const gsl_vector_float"是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40849025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com