我正在尝试使用C中BLAS库的zgemm函数将复数向量乘以复杂矩阵。
这是我正在使用的代码:
void dot(complexArray* mat1, char transa, complexArray* mat2, char transb, complexArray* out)
{
ptrdiff_t m = (ptrdiff_t)mat1->m;
ptrdiff_t n = (ptrdiff_t)mat2->n;
ptrdiff_t k = (ptrdiff_t)mat1->n;
ptrdiff_t lda = (ptrdiff_t)mat1->m;
ptrdiff_t ldb = (ptrdiff_t)mat2->m;
ptrdiff_t ldc = (ptrdiff_t)out->m;
//scalar factors
double alpha[2] = {1,0};
double beta[2] = {0,0};
//BLAS routine for complex matrix multiplication
zgemm(&transa, &transb, &m, &n, &k, alpha, mat1->data, &lda, mat2->data,
&ldb, beta, out->data, &ldc);
}
complexArray结构定义如下:
typedef struct
{
double* data;
size_t m;
size_t n;
} complexArray;
但是,如果我通过
调用点函数dot(array1, 'C', array2, 'N', resultArray);
其中array1.m == r,array1.n == 1和array2.m == array2.n == r,我收到类似
的内容216692908932268360000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000 + 4451969616001722900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.0000i
由于对变量transa使用与参数'N'相同的函数(当然对于不同形状的向量/矩阵组合),我担心我误解了transa参数。可以找到错误的任何提示?
答案 0 :(得分:1)
好的,我想我在BLAS函数的FORTRAN文档中找到了答案(参见例如dgemm documentation:
参数M,N和K(在我的情况下为m,n和k)不是指原始矩阵的行和列,而是指最终使用的矩阵,即转置或共轭矩阵。因此,如果你使用' T'或者' C' TRANSA或TRANSB参数的选项,请确保您还分别交换M和N或N和K.