2014-02-26 60 views
0

我試圖使用BLAS庫的ZGEMM功能C.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  

由於使用相同的功能與參數'N'也用於變量transa(當然對於不同形狀的矢量/矩陣組合),我擔心我誤解了transa參數。任何提示錯誤可能位於哪裏?

+0

並且'out'的'data'已被正確分配? –

+0

我會這麼說:所有complexArray數據都以相同的方式分配:$ data =(double *)mxMalloc (2 * m * n * sizeof(double)); $。在這裏情況下,m == n == 1;因此,分配具有兩個字段的雙數組以便存儲結果的實部和虛部。 – Michael

回答

1

好吧,我想我已經找到了BLAS函數的FORTRAN文檔中的答案(見如dgemm documentation

參數M,N和K(在我的情況M,N和K)不涉及到原始矩陣的行和列,而是到最終使用的矩陣,即轉置或共軛矩陣。因此,如果對TRANSA或TRANSB參數使用'T'或'C'選項,請確保您也交換M和N或N和K分別爲