Outer product using CBLAS

Posted by The Dude on Stack Overflow See other posts from Stack Overflow or by The Dude
Published on 2013-11-07T19:37:40Z Indexed on 2013/11/08 3:54 UTC
Read the original article Hit count: 134

I am having trouble utilizing CBLAS to perform an Outer Product. My code is as follows:

//===SET UP===//
double x1[] = {1,2,3,4};
double x2[] = {1,2,3};
int dx1 = 4;
int dx2 = 3;
double X[dx1 * dx2];
for (int i = 0; i < (dx1*dx2); i++) {X[i] = 0.0;}

//===DO THE OUTER PRODUCT===//
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasTrans, dx1, dx2, 1, 1.0, x1, dx1, x2, 1, 0.0, X, dx1);

//===PRINT THE RESULTS===//
printf("\nMatrix X (%d x %d) = x1 (*) x2 is:\n", dx1, dx2);
for (i=0; i<4; i++) {
    for (j=0; j<3; j++) {
        printf ("%lf ", X[j+i*3]);
    }
    printf ("\n");
}

I get:

Matrix X (4 x 3) = x1 (*) x2 is:
1.000000 2.000000 3.000000 
0.000000 -1.000000 -2.000000 
-3.000000 0.000000 7.000000 
14.000000 21.000000 0.000000 

But the correct answer is found here: https://www.sharcnet.ca/help/index.php/BLAS_and_CBLAS_Usage_and_Examples

I have seen: Efficient computation of kronecker products in C

But, it doesn't help me because they don't actually say how to utilize dgemm to actually do this...

Any help? What am I doing wrong here?

© Stack Overflow or respective owner

Related posts about c

    Related posts about linear-algebra