neuralNetworkTests implementiert

This commit is contained in:
dehmfl103364 committed 2026-11-06 11:05:46 +01:00
1 parent 4a391e4319
commit b84fccd39c
3 files changed
+33 -11

No files matched your search

-8
View File
@@ -79,14 +79,6 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
} }
} }
Matrix multiply(const Matrix matrix1, const Matrix matrix2) Matrix multiply(const Matrix matrix1, const Matrix matrix2)
+1 -1
View File
@@ -71,7 +71,7 @@ static unsigned int readDimension(FILE *file)
return dimension; 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); Matrix matrix = createMatrix(rows, cols);
+32 -2
View File
@@ -4,11 +4,41 @@
#include <math.h> #include <math.h>
#include "unity.h" #include "unity.h"
#include "neuralNetwork.h" #include "neuralNetwork.h"
#define FILE_HEADER_STRING "__info2_neural_network_file_format__"
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) 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) void test_loadModelReturnsCorrectNumberOfLayers(void)