generated from freudenreichan/info2Praktikum-NeuronalesNetz
Bugfixing, V2
This commit is contained in:
parent
0c19c17d68
commit
4640908e1b
14
matrix.c
14
matrix.c
@ -75,10 +75,12 @@ return MatrixErgebnis;
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
Matrix result;
|
||||
result.rows = matrix1.rows;
|
||||
result.cols = matrix2.cols;
|
||||
|
||||
if (matrix1.rows == matrix2.cols) {
|
||||
Matrix result;
|
||||
result.rows = matrix1.rows;
|
||||
result.cols = matrix2.cols;
|
||||
|
||||
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
|
||||
|
||||
@ -86,13 +88,13 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
for(int j = 0; j < result.cols; j++) {
|
||||
MatrixType value = 0;
|
||||
for(int k = 0; k < matrix1.cols; k++) {
|
||||
value += matrix1.buffer[i][k] * matrix2.buffer[k][j];
|
||||
value += matrix1.buffer[i * matrix1.cols + k] * matrix2.buffer[k * matrix2.cols + j];
|
||||
}
|
||||
result.buffer[i][j] = value;
|
||||
result.buffer[i * matrix1.cols + j] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
printf("Die angegebenen Matrizen haben keine passenden Dimensionen für die Multiplikation");
|
||||
return NULL;
|
||||
return result;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user