我试图使用cgemv_函数将复数矩阵与复数向量相乘,但结果并不是我所期望的。 我尝试使用简单的单位矩阵乘法运行函数:
complex *A, *B, *C;
int dimM, dimK, i;
char TRANS;
complex ALPHA, BETA;
int LDA, INCX, INCY;
dimM = 3;
dimK = 3;
A = new complex[dimM*dimK];
B = new complex[dimK];
C = new complex[dimM];
A[0] = complex(1.0, 0.0);
A[1] = complex(0.0, 0.0);
A[2] = complex(0.0, 0.0);
A[3] = complex(0.0, 0.0);
A[4] = complex(1.0, 0.0);
A[5] = complex(0.0, 0.0);
A[6] = complex(0.0, 0.0);
A[7] = complex(0.0, 0.0);
A[8] = complex(1.0, 0.0);
B[0] = complex(1.0, 0.0);
B[1] = complex(3.0, 0.0);
B[2] = complex(2.0, 0.0);
TRANS = 'N';
ALPHA = complex(1.0, 0.0);
BETA = complex(0.0, 0.0);
LDA = dimM;
INCX = 1;
INCY = 1;
cgemv_(&TRANS,&dimM,&dimK,&ALPHA,A,&LDA,B,&INCX,&BETA,C,&INCY);
for(i=0 ; i < dimM ; i++) {
printf("(%lf, %lf)\n", C[i].real(), C[i].imag());
}
但我得到的结果并不像我期待的那样(1,3,2),而是:
(-19392.000000, 0.000000)
(-63616.000000, 0.000000)
(0.000000, 0.000000)