Compare commits

..

No commits in common. "patric" and "main" have entirely different histories.
patric ... main

2 changed files with 5 additions and 38 deletions

View File

@ -16,48 +16,20 @@ void clearMatrix(Matrix *matrix)
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{ {
matrix.data[rowIdx][colIdx] = value;
} }
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
{ {
MatrixType value = matrix.data[rowIdx][colIdx];
return value;
} }
Matrix add(const Matrix matrix1, const Matrix matrix2) Matrix add(const Matrix matrix1, const Matrix matrix2)
{ {
Matrix invalidResult = {0};
if (
matrix1.rows == 0 || matrix1.cols == 0 || matrix2.rows == 0 || matrix2.cols == 0 ||
matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols ||
matrix1.data == NULL || matrix2.data == NULL
)
{
return invalidResult;
}
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
if (result.data == NULL)
return invalidResult;
for (unsigned int row = 0; row < matrix1.rows; row++)
{
MatrixType *dstRow = result.data[row];
MatrixType *row1 = matrix1.data[row];
MatrixType *row2 = matrix2.data[row];
for (unsigned int col = 0; col < matrix1.cols; col++)
{
dstRow[col] = row1[col] + row2[col];
}
}
return result;
} }
Matrix multiply(const Matrix matrix1, const Matrix matrix2) Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{ {
} }

View File

@ -5,12 +5,7 @@
typedef float MatrixType; typedef float MatrixType;
typedef struct // TODO Matrixtyp definieren
{
MatrixType **data;
unsigned int rows;
unsigned int cols;
} Matrix;
Matrix createMatrix(unsigned int rows, unsigned int cols); Matrix createMatrix(unsigned int rows, unsigned int cols);