forked from freudenreichan/info2Praktikum-NeuronalesNetz
Compare commits
2 Commits
ebff958c4e
...
42e92f278f
| Author | SHA1 | Date | |
|---|---|---|---|
| 42e92f278f | |||
| 14388a5637 |
17
matrix.c
17
matrix.c
@ -94,7 +94,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
}
|
||||
|
||||
result.rows = matrix1.rows;
|
||||
result.cols = matrix1.cols;
|
||||
result.cols = matrix2.cols;
|
||||
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
|
||||
|
||||
// wenn buffer nicht allokiert werden kann dann zurücksetzen und abbrechen
|
||||
@ -106,16 +106,19 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
}
|
||||
|
||||
// Matritzenmultiplikation
|
||||
for (unsigned int i = 0; i < result.rows; i++)
|
||||
for (int r = 0; r < result.rows; r++) // Zeile in Ergebnis
|
||||
{
|
||||
for (unsigned int j = 0; j < result.cols; j++)
|
||||
for (int m = 0; m < result.cols; m++) // Spalte in Ergebnis
|
||||
{
|
||||
MatrixType sum = 0;
|
||||
for (unsigned int k = 0; k < matrix1.cols; k++)
|
||||
MatrixType sum = 0;
|
||||
|
||||
for (int n = 0; n < matrix1.cols; n++)
|
||||
{
|
||||
sum += matrix1.buffer[i * matrix1.cols + k] * matrix2.buffer[k * matrix2.cols + j];
|
||||
sum += matrix1.buffer[r * matrix1.cols + n] *
|
||||
matrix2.buffer[n * matrix2.cols + m];
|
||||
}
|
||||
result.buffer[i * result.cols + j] = sum;
|
||||
|
||||
result.buffer[r * result.cols + m] = sum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user