forked from freudenreichan/info2Praktikum-NeuronalesNetz
implement matmul
This commit is contained in:
parent
645d471860
commit
0d7f380d87
21
matrix.c
21
matrix.c
@ -113,4 +113,25 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
// TODO implement
|
// TODO implement
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
if (matrix1.cols != matrix2.rows || matrix1.buffer == NULL || matrix2.buffer == NULL)
|
||||||
|
{
|
||||||
|
return createMatrix(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int rows = matrix1.rows, cols = matrix2.cols;
|
||||||
|
Matrix resMat = createMatrix(rows, cols);
|
||||||
|
|
||||||
|
for (size_t rowIdx = 0; rowIdx < rows; rowIdx++)
|
||||||
|
{
|
||||||
|
for (size_t colIdx = 0; colIdx < cols; colIdx++)
|
||||||
|
{
|
||||||
|
int curCellVal = 0;
|
||||||
|
for (size_t k = 0; k < matrix1.cols; k++)
|
||||||
|
{
|
||||||
|
curCellVal += getMatrixAt(matrix1, rowIdx, k) * getMatrixAt(matrix2, k, colIdx);
|
||||||
|
}
|
||||||
|
setMatrixAt(curCellVal, resMat, rowIdx, colIdx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resMat;
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user