neuralNetworkTests implementiert

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

No files matched your search

+33 -3
View File
@@ -4,11 +4,41 @@
#include <math.h>
#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)