我正在使用cblass_dgemm来乘以两个矩阵
应该计算B = A'x A;
row_train = 10304, col_train = 5;
gsl_matrix *mean_centred_train = gsl_matrix_alloc(row_train, col_train);
gsl_matrix * image_for_eigen = gsl_matrix_alloc(col_train, col_train);
这就是我所说的:
cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans, mean_centred_train->size1, mean_centred_train->size2, mean_centred_train->size2, 1, mean_centred_train->data, mean_centred_train->size1, mean_centred_train->data, mean_centred_train->size1, 1, image_for_eigen->data, image_for_eigen->size1);
当我运行程序时,我遇到了分段错误,我很确定矩阵的大小是正确的。
答案 0 :(得分:1)
应该是这样的。
cblas_dgemm(CblasRowMajor, CblasTrans, CblasNoTrans,
image_for_eigen->size1, //m
image_for_eigen ->size2, //n
mean_centred_train->size1, //k
1.0, //alpha
mean_centred_train->data, mean_centred_train->size1,
mean_centred_train->data, mean_centred_train->size1,
0.0, //beta
image_for_eigen->data, image_for_eigen->size1);
[m, n]
是结果矩阵的大小,无论输入矩阵是否被转置。如果您需要beta
,0.0
也应为B=A'*A
。