diff --git a/makefile b/makefile index f27b756..67a3c53 100644 --- a/makefile +++ b/makefile @@ -57,10 +57,11 @@ imageInputTests: imageInput.o imageInputTests.c $(unityfolder)/unity.c # -------------------------- # Clean # -------------------------- +#clean: +#ifeq ($(OS),Windows_NT) +# del /f *.o *.exe +#else +# rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests +#endif clean: -ifeq ($(OS),Windows_NT) - del /f *.o *.exe -else - rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests -endif - + rm -f *.o *.exe \ No newline at end of file diff --git a/matrix.c b/matrix.c index f1a06f3..6cd833e 100644 --- a/matrix.c +++ b/matrix.c @@ -1,36 +1,38 @@ +#include "matrix.h" #include #include -#include "matrix.h" - // TODO Matrix-Funktionen implementieren - -Matrix createMatrix(unsigned int rows, unsigned int cols) -{ - MatrixType* data = malloc(rows * cols * sizeof(MatrixType)); - Matrix newMatrix = {rows, cols, data}; - return newMatrix; +/*typedef struct { + unsigned int rows; //Zeilen + unsigned int cols; //Spalten + MatrixType *data; //Zeiger auf Speicherbereich Reihen*Spalten +} Matrix;*/ +Matrix createMatrix(unsigned int rows, unsigned int cols) { + MatrixType *data = + malloc(rows * cols * sizeof(MatrixType)); // Speicher reservieren, malloc + // liefert Zeiger auf Speicher + Matrix newMatrix = {rows, cols, data}; // neue Matrix nach struct + return newMatrix; } - -void clearMatrix(Matrix *matrix) -{ +void clearMatrix(Matrix *matrix) { + matrix->data = UNDEFINED_MATRIX_VALUE; + matrix->rows = UNDEFINED_MATRIX_VALUE; + matrix->cols = UNDEFINED_MATRIX_VALUE; + free((*matrix).data); // Speicher freigeben } - -void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) -{ - +void setMatrixAt(MatrixType value, Matrix matrix, + unsigned int rowIdx, // Kopie der Matrix wird übergeben + unsigned int colIdx) { + matrix.data[rowIdx * matrix.cols + colIdx] = + value; // rowIdx * matrix.cols -> Beginn der Zeile colIdx ->Spalte + // innerhalb der Zeile } - -MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) -{ - +MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, + unsigned int colIdx) { + return 0; } - -Matrix add(const Matrix matrix1, const Matrix matrix2) -{ - +Matrix add(const Matrix matrix1, const Matrix matrix2) { + // broadcasting + return matrix1; } - -Matrix multiply(const Matrix matrix1, const Matrix matrix2) -{ - -} \ No newline at end of file +Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; } diff --git a/matrix.h b/matrix.h index 736e6e1..1d37962 100644 --- a/matrix.h +++ b/matrix.h @@ -6,20 +6,20 @@ typedef float MatrixType; // TODO Matrixtyp definieren -typedef struct -{ - unsigned int rows; - unsigned int cols; - MatrixType *data; -} Matrix; +typedef struct { + unsigned int rows; + unsigned int cols; + MatrixType *data; +} Matrix; Matrix createMatrix(unsigned int rows, unsigned int 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); +void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, + unsigned int colIdx); +MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, + unsigned int colIdx); Matrix add(const Matrix matrix1, const Matrix matrix2); Matrix multiply(const Matrix matrix1, const Matrix matrix2); - #endif