diff --git a/matrix.c b/matrix.c index 4e9be5c..1062261 100644 --- a/matrix.c +++ b/matrix.c @@ -131,4 +131,14 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) } } return result; +} +void writeMatrix(Matrix matrix, FILE *file)//Added for neuralNetworkTests +{ + for(int i = 0; i < matrix.rows; i++) + { + for(int j = 0; j < matrix.cols; j++) + { + fprintf(file, (char*)(matrix.buffer + (j+i)*sizeof(MatrixType))); + } + } } \ No newline at end of file diff --git a/matrix.h b/matrix.h index 0771157..15b943e 100644 --- a/matrix.h +++ b/matrix.h @@ -21,6 +21,7 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned 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); +void writeMatrix(Matrix matrix, FILE *file);//Added for neuralNetworkTests #endif diff --git a/neuralNetworkTests.c b/neuralNetworkTests.c index 21ab370..1647ab1 100644 --- a/neuralNetworkTests.c +++ b/neuralNetworkTests.c @@ -4,11 +4,20 @@ #include #include "unity.h" #include "neuralNetwork.h" +#include "matrix.h" static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) { - // TODO + FILE *testDatei = fopen(path, "w"); + fprintf(testDatei, "__info2_neural_network_file_format__"); + for(int i = 0; i < nn.numberOfLayers; i++) + { + fprintf(testDatei, "\n"); + writeMatrix(nn.layers[i].weights, testDatei); + writeMatrix(nn.layers[i].biases, testDatei); + } + fclose(testDatei); } void test_loadModelReturnsCorrectNumberOfLayers(void)