forked from freudenreichan/info2Praktikum-NeuronalesNetz
multiply
This commit is contained in:
1 parent
85369b3bad
commit
d4e329e098
1 file changed
+24
@@ -103,5 +103,29 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
|
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
if(matrix.cols !=matrix2.rows){
|
||||||
|
Matrix result;
|
||||||
|
result.rows = 0;
|
||||||
|
result.cols = 0;
|
||||||
|
result.buffer = NULL;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix resultMatrix = createMatrix(matrix1.rows, matrix2.cols);
|
||||||
|
if (resultMatrix.buffer == NULL) {
|
||||||
|
return resultMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < matrix1.rows; i++) {
|
||||||
|
for (unsigned int j = 0; j < matrix2.cols; j++) {
|
||||||
|
MatrixType sum = 0;
|
||||||
|
for (unsigned int k = 0; k < matrix1.cols; k++) {
|
||||||
|
sum += getMatrixAt(matrix1, i, j) * getMatrixAt(matrix2, k, j);
|
||||||
|
}
|
||||||
|
setMatrixAt(sum, resultMatrix, i, j);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultMatrix;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user