加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – BLAS中的元素向量向量乘法?

发布时间:2020-12-16 05:29:42 所属栏目:百科 来源:网络整理
导读:有没有办法用BLAS,GSL或任何其他高性能库进行元素向量向量乘法? 解决方法 (以字面上的题目标题…) 是的,可以单独使用BLAS(尽管它可能不是最有效的方式). 诀窍在于将一个输入向量作为对角线矩阵: ?a ? ?x? ?ax?? b ? ?y? = ?by?? c? ?z? ?cz? 然后,您可以使
有没有办法用BLAS,GSL或任何其他高性能库进行元素向量向量乘法?

解决方法

(以字面上的题目标题…)

是的,可以单独使用BLAS(尽管它可能不是最有效的方式).

诀窍在于将一个输入向量作为对角线矩阵:

?a    ? ?x?    ?ax?
?  b  ? ?y? =  ?by?
?    c? ?z?    ?cz?

然后,您可以使用矩阵向量乘法函数中的一个,该函数可以将对角矩阵作为输入,而不需要填充,例如. SBMV

例:

void ebeMultiply(const int n,const double *a,const double *x,double *y)
{
    extern void dsbmv_(const char *uplo,const int *n,const int *k,const double *alpha,const int *lda,const int *incx,const double *beta,double *y,const int *incy);

    static const int k = 0; // Just the diagonal; 0 super-diagonal bands
    static const double alpha = 1.0;
    static const int lda = 1;
    static const int incx = 1;
    static const double beta = 0.0;
    static const int incy = 1;

    dsbmv_("L",&n,&k,&alpha,a,&lda,x,&incx,&beta,y,&incy);
}

// Test
#define N 3
static const double a[N] = {1,3,5};
static const double b[N] = {1,10,100};
static double c[N];

int main(int argc,char **argv)
{
    ebeMultiply(N,b,c);
    printf("Result: [%f %f %f]n",c[0],c[1],c[2]);
    return 0;
}

结果:[1.000000 30.000000 500.000000]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读