forked from freudenreichan/info2Praktikum-NeuronalesNetz
MatrixMult vollständig, data in buffer umbenannt, damit passend zu MatrixTests. 5 Tests bestanden, 7 fehlgeschlagen. Fehlersuche läuft
This commit is contained in:
1 parent
4a31d6388d
commit
0ee879ba20
1 file changed
+24
-5
+24
-5
@@ -9,24 +9,28 @@ Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
Matrix matrix;
|
||||
matrix.rows = rows;
|
||||
matrix.cols = cols;
|
||||
matrix.data = malloc(rows * cols * sizeof(MatrixType));
|
||||
|
||||
matrix.buffer = NULL;
|
||||
if (rows == 0 || cols == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
matrix.buffer = malloc(rows * cols * sizeof(MatrixType));
|
||||
return matrix;
|
||||
}
|
||||
|
||||
void clearMatrix(Matrix *matrix)
|
||||
{
|
||||
free(matrix->data);
|
||||
free(matrix->buffer);
|
||||
}
|
||||
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
matrix.data[rowIdx * matrix.cols + colIdx] = value;
|
||||
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
||||
}
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
MatrixType MatrixAt = matrix.data[rowIdx * matrix.cols + colIdx];
|
||||
MatrixType MatrixAt = matrix.buffer[rowIdx * matrix.cols + colIdx];
|
||||
return MatrixAt;
|
||||
}
|
||||
|
||||
@@ -48,4 +52,19 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
Matrix MatrixMult = createMatrix(matrix1.rows, matrix2.cols);
|
||||
for (int i = 0; i < matrix1.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < matrix2.cols; j++)
|
||||
{
|
||||
MatrixType skalar = 0;
|
||||
for (int k = 0; k < matrix1.cols; k++)
|
||||
{
|
||||
MatrixType val1 = getMatrixAt(matrix1, i, k);
|
||||
MatrixType val2 = getMatrixAt(matrix2, k, j);
|
||||
skalar += val1 * val2;
|
||||
}
|
||||
setMatrixAt(skalar, MatrixMult, i, j);
|
||||
}
|
||||
}
|
||||
return MatrixMult;
|
||||
}
|
||||
Reference in new issue
Block a user