bit of vibe coding in matrix.c
This commit is contained in:
parent
b488c5bf55
commit
da0dddd975
36
matrix.c
36
matrix.c
@ -16,20 +16,48 @@ 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)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
7
matrix.h
7
matrix.h
@ -5,7 +5,12 @@
|
|||||||
|
|
||||||
typedef float MatrixType;
|
typedef float MatrixType;
|
||||||
|
|
||||||
// TODO Matrixtyp definieren
|
typedef struct
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user