Tal_
Tal_

Reputation: 761

cblas_dgemm segmentation fault

I'm using cblass_dgemm to multiply two matrices

It is supposed to calculate 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);

This is how I call it:

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);

And when I run the program I get a segmentation fault, and I'm pretty sure the sizes of matrices are correct.

Upvotes: 0

Views: 765

Answers (1)

kangshiyin
kangshiyin

Reputation: 9781

It should be like this.

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] are size of the result matrix, no matter the input matrices are transposed or not. Also beta should be 0.0 if you want B=A'*A.

Upvotes: 1

Related Questions