forked from freudenreichan/info2Praktikum-NeuronalesNetz
Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
fd5b5f6196
1 file changed
+11
-9
+11
-9
@@ -63,14 +63,18 @@ MatrixType getMatrixAt(const Matrix matrix,
|
|||||||
// Zwei Matrizen addieren
|
// Zwei Matrizen addieren
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
// Dimensionen und Buffer überprüfen
|
||||||
if (matrix1.rows != matrix2.rows ||
|
if (matrix1.rows != matrix2.rows ||
|
||||||
matrix1.cols != matrix2.cols ||
|
matrix1.cols != matrix2.cols ||
|
||||||
|
matrix1.rows == 0 ||
|
||||||
|
matrix1.cols == 0 ||
|
||||||
matrix1.buffer == NULL ||
|
matrix1.buffer == NULL ||
|
||||||
matrix2.buffer == NULL)
|
matrix2.buffer == NULL)
|
||||||
{
|
{
|
||||||
return createMatrix(0, 0);
|
return createMatrix(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ergebnismatrix erstellen
|
||||||
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
|
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
|
||||||
|
|
||||||
if (result.buffer == NULL)
|
if (result.buffer == NULL)
|
||||||
@@ -78,21 +82,18 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < matrix1.rows; i++)
|
// Matrizen elementweise addieren
|
||||||
{
|
unsigned int size = matrix1.rows * matrix1.cols;
|
||||||
for (unsigned int j = 0; j < matrix1.cols; j++)
|
|
||||||
{
|
|
||||||
MatrixType value =
|
|
||||||
getMatrixAt(matrix1, i, j) +
|
|
||||||
getMatrixAt(matrix2, i, j);
|
|
||||||
|
|
||||||
setMatrixAt(value, result, i, j);
|
for (unsigned int i = 0; i < size; i++)
|
||||||
}
|
{
|
||||||
|
result.buffer[i] = matrix1.buffer[i] + matrix2.buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Zwei Matrizen multiplizieren
|
// Zwei Matrizen multiplizieren
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
@@ -123,6 +124,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
setMatrixAt(sum, result, i, j);
|
setMatrixAt(sum, result, i, j);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user