generated from freudenreichan/info2Praktikum-NeuronalesNetz
creatMatrix, clearMatrix, setMatrixAt implementiert
This commit is contained in:
1 parent
a40f7788b0
commit
d31214f974
2 files changed
+31
-5
No files matched your search
+25
-5
@@ -6,30 +6,50 @@
|
|||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
|
Matrix matrix = {NULL,rows,cols};
|
||||||
|
if(rows != 0 && cols != 0){
|
||||||
|
matrix.buffer = calloc(rows * cols, sizeof(MatrixType));
|
||||||
|
if(matrix.buffer == NULL){
|
||||||
|
matrix.rows = 0;
|
||||||
|
matrix.cols = 0; // alternativ Programm beenden mit exit -> so einfach dimensionslos
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
matrix.rows = 0;
|
||||||
|
matrix.cols = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearMatrix(Matrix *matrix)
|
void clearMatrix(Matrix *matrix)
|
||||||
{
|
{
|
||||||
|
free(matrix->buffer);
|
||||||
|
matrix->buffer = NULL;
|
||||||
|
matrix->rows = 0;
|
||||||
|
matrix->cols = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
|
if(matrix.rows > rowIdx && matrix.cols > colIdx){
|
||||||
|
matrix.buffer[colIdx + rowIdx * matrix.cols] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
|
MatrixType testHelp = 0;
|
||||||
|
return testHelp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
Matrix testHelp = {NULL, 0,0};
|
||||||
|
return testHelp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
|
Matrix testHelp = {NULL, 0,0};
|
||||||
|
return testHelp;
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,12 @@ typedef float MatrixType;
|
|||||||
|
|
||||||
// TODO Matrixtyp definieren
|
// TODO Matrixtyp definieren
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
MatrixType* buffer;
|
||||||
|
unsigned int rows;
|
||||||
|
unsigned int cols;
|
||||||
|
}Matrix;
|
||||||
|
|
||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
||||||
void clearMatrix(Matrix *matrix);
|
void clearMatrix(Matrix *matrix);
|
||||||
|
|||||||
Reference in new issue
Block a user