1

I've written the following function for matrix multiplication using DGEMM. It takes three matrices a, b and c as double arrays and calculates axb=c. The three integers rowsA, colsB und colsA_rowsB are used by DGEMM to use the correct dimensions. Thee boolean trans is supposed to give the option to use the transpose of matrix b in the calculation, specifically axb^T=c.

void SvdUtility::getMatrixProduct(double a[], double b[], double c[], int rowsA, int colsA_rowsB, int colsB, bool trans)
{
    if (trans)
    {
        cblas_dgemm(CblasColMajor, CblasNoTrans, CblasTrans, rowsA, colsB, colsA_rowsB, 1, a, rowsA, b, colsA_rowsB, 0, c, rowsA);
    }
    else
    {

        cblas_dgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, rowsA, colsB, colsA_rowsB, 1, a, rowsA, b, colsA_rowsB, 0, c, rowsA);
    }
}

Now when I test my function with the following code it works just fine when I'm not transposing (first method call) but when I do (second method call) I get ** On entry to DGEMM parameter number 8 had an illegal value

double six[] {
    2, 3, 5, 7, 11, 13
};

double four[] {
    2, 3, 5, 7
};

double* test = new double[6];

SvdUtility::getMatrixProduct(six, four, test, 3, 2, 2, false);

SvdUtility::getMatrixProduct(six, four, test, 3, 2, 2, true);

I don't understand. The matrix that gets transposed is square, so dimensions shouldn't be a problem. Where am I wrong?

dYTe
  • 191
  • 1
  • 8
  • Out of curiosity, and cause I don't see a mistake right away, what happens, if you run the two products in reverse order, i.e. the 6*4^T first then 6*4. Anyway here is my C++ code that works and is battle tested and does all prevcisions, complex and real: https://github.com/kvahed/codeare/blob/master/src/matrix/linalg/Lapack.hpp Maybe you can find the error. – Kaveh Vahedipour Mar 04 '19 at 11:21
  • `parameter 8` is of course `rowsA` so it does seem odd to be wrong when you transpose b. Which implementation are you linking against? – Kaveh Vahedipour Mar 04 '19 at 11:40

0 Answers0