generated from freudenreichan/info2Praktikum-NeuronalesNetz
asdf
This commit is contained in:
parent
cdd14986cf
commit
8b1eecfb5c
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
mnist
|
||||
runTests
|
||||
runMatrixTests
|
||||
*.o
|
||||
*.exe
|
||||
41
matrix.c
41
matrix.c
@ -4,22 +4,24 @@
|
||||
|
||||
// TODO Matrix-Funktionen implementieren
|
||||
|
||||
/*
|
||||
Alte Funktion
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
{
|
||||
Matrix m;
|
||||
m.xElement = rows;
|
||||
m.yElement = cols;
|
||||
m.rows = rows;
|
||||
m.cols = cols;
|
||||
m.data = NULL;
|
||||
|
||||
if(rows == 0 || cols == 0){
|
||||
m.xElement = m.yElement = 0;
|
||||
m.rows = m.cols = 0;
|
||||
return m;
|
||||
}
|
||||
|
||||
m.data = malloc(rows * sizeof *m.data);
|
||||
|
||||
if(!m.data){
|
||||
m.xElement = m.yElement = 0;
|
||||
m.rows = m.cols = 0;
|
||||
return m;
|
||||
}
|
||||
for(unsigned int i = 0; i < rows; i++){
|
||||
@ -31,13 +33,42 @@ Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
}
|
||||
free(m.data);
|
||||
m.data = NULL;
|
||||
m.xElement = m.yElement = 0;
|
||||
m.rows = m.cols = 0;
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
return m;
|
||||
}
|
||||
*/
|
||||
|
||||
Matrix createMatrix(size_t rows, size_t cols)
|
||||
{
|
||||
Matrix m;
|
||||
m.rows = rows;
|
||||
m.cols = cols;
|
||||
m.buffer = NULL;
|
||||
|
||||
if(rows == 0 || cols == 0){
|
||||
m.rows = m.cols = 0;
|
||||
return m;
|
||||
}
|
||||
|
||||
// Single allocation for entire matrix
|
||||
m.buffer = malloc(rows * cols * sizeof(MatrixType));
|
||||
|
||||
if(!m.buffer){
|
||||
m.rows = m.cols = 0;
|
||||
return m;
|
||||
}
|
||||
|
||||
// Initialize (optional)
|
||||
for(unsigned int i = 0; i < rows * cols; i++){
|
||||
m.buffer[i] = UNDEFINED_MATRIX_VALUE;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void clearMatrix(Matrix *matrix)
|
||||
{
|
||||
|
||||
8
matrix.h
8
matrix.h
@ -7,13 +7,13 @@ typedef float MatrixType;
|
||||
// TODO Matrixtyp definieren
|
||||
|
||||
typedef struct Matrix {
|
||||
unsigned int xElement;
|
||||
unsigned int yElement;
|
||||
double ** data;
|
||||
size_t rows;
|
||||
size_t cols;
|
||||
MatrixType *buffer;
|
||||
} Matrix;
|
||||
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
||||
Matrix createMatrix(size_t rows, size_t cols);
|
||||
void clearMatrix(Matrix *matrix);
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx);
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user