generated from freudenreichan/info2Praktikum-NeuronalesNetz
Compare commits
3 Commits
2f3ddb1232
...
32cf681534
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32cf681534 | ||
|
|
8b1eecfb5c | ||
|
|
cdd14986cf |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
mnist
|
||||
runTests
|
||||
runMatrixTests
|
||||
*.o
|
||||
*.exe
|
||||
48
matrix.c
48
matrix.c
@ -4,28 +4,24 @@
|
||||
|
||||
// TODO Matrix-Funktionen implementieren
|
||||
|
||||
typedef struct Matrix {
|
||||
unsigned int xElement;
|
||||
unsigned int yElement;
|
||||
int ** data;
|
||||
} Matrix;
|
||||
|
||||
/*
|
||||
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++){
|
||||
@ -37,13 +33,43 @@ 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 cols, size_t rows)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
9
matrix.h
9
matrix.h
@ -4,11 +4,16 @@
|
||||
#define UNDEFINED_MATRIX_VALUE 0
|
||||
|
||||
typedef float MatrixType;
|
||||
|
||||
// TODO Matrixtyp definieren
|
||||
|
||||
typedef struct Matrix {
|
||||
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