forked from freudenreichan/info2Praktikum-NeuronalesNetz
create und clear Matrix
This commit is contained in:
1 parent
558027418c
commit
5832db7c2e
1 file changed
+12
-1
+12
-1
@@ -6,11 +6,22 @@
|
|||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
|
Matrix m;
|
||||||
|
m.rows = rows;
|
||||||
|
m.cols = cols;
|
||||||
|
m.data = (MatrixType*) calloc(rows * cols, sizeof(MatrixType)); // calloc, statt malloc benutzt, um direkt alle Werte mit 0 zu initialisieren
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearMatrix(Matrix *matrix)
|
void clearMatrix(Matrix *matrix)
|
||||||
{
|
{
|
||||||
|
if(matrix == NULL){ // falls clearMatrix(NULL) aufgerufen wird, sonst würde es abstürzen, wenn mann direkt free(matrix->data) schreibt
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free(matrix->data); // matrix->data = (*matrix).data
|
||||||
|
matrix->data = NULL; // falls clearMatrix doppelt aufgerufen wird
|
||||||
|
matrix->rows = 0; // Matrix wird als komplett leer markiert
|
||||||
|
matrix->cols = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user