使用1d阵列的矩阵乘法 [英] Matrix multiplication using 1d arrays
本文介绍了使用1d阵列的矩阵乘法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图将存储在1d数组中的两个矩阵相乘。
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;
}
}
我错了?
感谢...
推荐答案
您的意思是
而不是
这篇关于使用1d阵列的矩阵乘法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文