diff --git a/Startcode/matrix.c b/Startcode/matrix.c index 21e51c1..50ed6e6 100644 --- a/Startcode/matrix.c +++ b/Startcode/matrix.c @@ -79,14 +79,6 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) } - - - - - - - - } Matrix multiply(const Matrix matrix1, const Matrix matrix2) diff --git a/Startcode/matrix.h b/Startcode/matrix.h index 9aead9a..4086afd 100644 --- a/Startcode/matrix.h +++ b/Startcode/matrix.h @@ -8,7 +8,7 @@ typedef float MatrixType; // TODO Matrixtyp definieren typedef struct{ - MatrixType* buffer; + MatrixType* buffer; unsigned int rows; unsigned int cols; }Matrix; diff --git a/Startcode/neuralNetwork.c b/Startcode/neuralNetwork.c index bd8f164..0e5ab02 100644 --- a/Startcode/neuralNetwork.c +++ b/Startcode/neuralNetwork.c @@ -71,7 +71,7 @@ static unsigned int readDimension(FILE *file) return dimension; } -static Matrix readMatrix(FILE *file, unsigned int rows, unsigned int cols) +static Matrix readMatrix(FILE *file, unsigned int rows, unsigned int cols) { Matrix matrix = createMatrix(rows, cols); diff --git a/Startcode/neuralNetworkTests.c b/Startcode/neuralNetworkTests.c index 21ab370..124feb8 100644 --- a/Startcode/neuralNetworkTests.c +++ b/Startcode/neuralNetworkTests.c @@ -4,11 +4,41 @@ #include #include "unity.h" #include "neuralNetwork.h" - +#define FILE_HEADER_STRING "__info2_neural_network_file_format__" static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) -{ - // TODO +{ + + FILE *testFile = fopen(path,"wb"); + unsigned int dimensionIn = nn.layers[0].weights.cols; + + if(testFile != NULL){ + fwrite(FILE_HEADER_STRING,sizeof(char) ,strlen(FILE_HEADER_STRING),testFile); + fwrite(&dimensionIn, sizeof(unsigned int), 1, testFile); + + for(unsigned int i = 0; i < nn.numberOfLayers; i++) { + + unsigned int dimensionOut = nn.layers[i].weights.rows; + fwrite(&dimensionOut, sizeof(int), 1, testFile); + + size_t weightsCount = nn.layers[i].weights.rows * nn.layers[i].weights.cols; + fwrite(nn.layers[i].weights.buffer, sizeof(MatrixType), weightsCount, testFile); + + + size_t biasesCount = nn.layers[i].biases.rows * nn.layers[i].biases.cols; + fwrite(nn.layers[i].biases.buffer, sizeof(MatrixType), biasesCount, testFile); + + } + const unsigned int finalDim = 0; + fwrite(&finalDim, sizeof(int), 1, testFile); + + + fclose(testFile); + } + + + + } void test_loadModelReturnsCorrectNumberOfLayers(void)