【发布时间】:2013-11-08 19:34:27
【问题描述】:
我在使用 CBLAS 执行外部产品时遇到问题。我的代码如下:
//===SET UP===//
double x1[] = {1,2,3,4};
double x2[] = {1,2,3};
int dx1 = 4;
int dx2 = 3;
double X[dx1 * dx2];
for (int i = 0; i < (dx1*dx2); i++) {X[i] = 0.0;}
//===DO THE OUTER PRODUCT===//
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans, dx1, dx2, 1, 1.0, x1, dx1, x2, 1, 0.0, X, dx1);
//===PRINT THE RESULTS===//
printf("\nMatrix X (%d x %d) = x1 (*) x2 is:\n", dx1, dx2);
for (i=0; i<4; i++) {
for (j=0; j<3; j++) {
printf ("%lf ", X[j+i*3]);
}
printf ("\n");
}
我明白了:
Matrix X (4 x 3) = x1 (*) x2 is:
1.000000 2.000000 3.000000
0.000000 -1.000000 -2.000000
-3.000000 0.000000 7.000000
14.000000 21.000000 0.000000
但正确答案在这里找到: https://www.sharcnet.ca/help/index.php/BLAS_and_CBLAS_Usage_and_Examples
我见过:Efficient computation of kronecker products in C
但是,这对我没有帮助,因为他们实际上并没有说明如何使用 dgemm 来实际执行此操作...
有什么帮助吗?我在这里做错了什么?
【问题讨论】:
标签: c linear-algebra scientific-computing numerical