I'm trying to multiply two matrices stored inside 1d arrays.
I'm using this function, but my program crashes, I assume due to an out of bounds error. However, I have no (easy) ability to debug, so I have to decide if my code is correct, and to me it seems it is...
void SampleUtils::multiplyMatrices(float* matA, int rA, int cA, float* matB,
int rB, int cB, float* matC, int rC, int cC) {
for (int i = 0; i <= rA; i++) {
for (int j = 0; j <= cB; j++) {
float sum = 0.0;
for (int k = 0; k <= rB; k++)
sum = sum + matA[i * cA + k] * matB[k * cB + j];
matC[i * cC + j] = sum;
}
}
So, can anyone find out what I did wrong?
Thanks...
rAis the number of rows of the matrix, then the condition must bei < rA. Similarly at other places.atto get an exception thrown if it is an out-of-bounds error.rBalways equal tocA, andrCis not used? Generally, I think you need only three sizes (ra=rC,rb=cA, andcb=cC, if I remember it correctly), not six; consider eliminating the unused parameters to reduce the confusion.