forked from freudenreichan/info2Praktikum-NeuronalesNetz
create und clear Matrix
This commit is contained in:
1 parent
558027418c
commit
5832db7c2e
1 file changed
+13
-2
+13
-2
@@ -6,12 +6,23 @@
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
|
||||
Reference in new issue
Block a user