generated from freudenreichan/info2Praktikum-NeuronalesNetz
Bugfixing, V2
This commit is contained in:
parent
0c19c17d68
commit
4640908e1b
10
matrix.c
10
matrix.c
@ -75,24 +75,26 @@ return MatrixErgebnis;
|
|||||||
|
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
if (matrix1.rows == matrix2.cols) {
|
|
||||||
Matrix result;
|
Matrix result;
|
||||||
result.rows = matrix1.rows;
|
result.rows = matrix1.rows;
|
||||||
result.cols = matrix2.cols;
|
result.cols = matrix2.cols;
|
||||||
|
|
||||||
|
if (matrix1.rows == matrix2.cols) {
|
||||||
|
|
||||||
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
|
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
|
||||||
|
|
||||||
for(int i = 0; i < result.rows; i++) {
|
for(int i = 0; i < result.rows; i++) {
|
||||||
for(int j = 0; j < result.cols; j++) {
|
for(int j = 0; j < result.cols; j++) {
|
||||||
MatrixType value = 0;
|
MatrixType value = 0;
|
||||||
for(int k = 0; k < matrix1.cols; k++) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
printf("Die angegebenen Matrizen haben keine passenden Dimensionen für die Multiplikation");
|
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