forked from freudenreichan/info2Praktikum-NeuronalesNetz
matrix pass all tests
This commit is contained in:
parent
42e92f278f
commit
e40a5cbd7b
9
matrix.c
9
matrix.c
@ -88,7 +88,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
{
|
{
|
||||||
Matrix result = {0};
|
Matrix result = {0};
|
||||||
|
|
||||||
if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
|
if (matrix1.cols != matrix2.rows)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -106,19 +106,20 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Matritzenmultiplikation
|
// Matritzenmultiplikation
|
||||||
|
|
||||||
for (int r = 0; r < result.rows; r++) // Zeile in Ergebnis
|
for (int r = 0; r < result.rows; r++) // Zeile in Ergebnis
|
||||||
{
|
{
|
||||||
for (int m = 0; m < result.cols; m++) // Spalte in Ergebnis
|
for (int m = 0; m < result.cols; m++) // Spalte in Ergebnis
|
||||||
{
|
{
|
||||||
MatrixType sum = 0;
|
MatrixType sum = 0;
|
||||||
|
|
||||||
for (int n = 0; n < matrix1.cols; n++)
|
for (int n = 0; n < matrix1.cols; n++)
|
||||||
{
|
{
|
||||||
sum += matrix1.buffer[r * matrix1.cols + n] *
|
sum += matrix1.buffer[r * matrix1.cols + n] *
|
||||||
matrix2.buffer[n * matrix2.cols + m];
|
matrix2.buffer[n * matrix2.cols + m];
|
||||||
}
|
}
|
||||||
|
|
||||||
result.buffer[r * result.cols + m] = sum;
|
result.buffer[r * result.cols + m] = sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user