forked from freudenreichan/info2Praktikum-NeuronalesNetz
setMatrix, getMatrix und Matrix add bearbeitet. Fehlermeldung bei Test von Matrix add, Ursache unbekannt. Liegt vielleicht an fehlender Implementierung von Matrix multiply
This commit is contained in:
1 parent
fc2b14d0e0
commit
240cc77288
1 file changed
+21
-3
+21
-3
@@ -9,7 +9,7 @@ Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
Matrix matrix;
|
||||
matrix.rows = rows;
|
||||
matrix.cols = cols;
|
||||
matrix.data = malloc(rows * cols * sizeof(MatrixType *));
|
||||
matrix.data = malloc(rows * cols * sizeof(MatrixType));
|
||||
|
||||
return matrix;
|
||||
}
|
||||
@@ -21,12 +21,30 @@ void clearMatrix(Matrix *matrix)
|
||||
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
matrix.data[rowIdx * matrix.cols + colIdx] = value;
|
||||
}
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
MatrixType MatrixAt = matrix.data[rowIdx * matrix.cols + colIdx];
|
||||
return MatrixAt;
|
||||
}
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2) {}
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
Matrix MatrixAdd = createMatrix(matrix1.rows, matrix1.cols);
|
||||
for (int i = 0; i < matrix1.rows; i++)
|
||||
{
|
||||
for (int j = 0; j < matrix1.cols; j++)
|
||||
{
|
||||
MatrixType val1 = getMatrixAt(matrix1, i, j);
|
||||
MatrixType val2 = getMatrixAt(matrix2, i, j);
|
||||
setMatrixAt(val1 + val2, MatrixAdd, i, j);
|
||||
}
|
||||
}
|
||||
return MatrixAdd;
|
||||
}
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2) {}
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
}
|
||||
Reference in new issue
Block a user