0

我正在使用 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);

当我运行程序时,我得到一个分段错误,我很确定矩阵的大小是正确的。

4

1 回答 1

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.0B=A'*A

于 2013-11-26T11:08:03.580 回答