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

-8
View File
@@ -79,14 +79,6 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
}
}
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
+1 -1
View File
@@ -8,7 +8,7 @@ typedef float MatrixType;
// TODO Matrixtyp definieren
typedef struct{
MatrixType* buffer;
MatrixType* buffer;
unsigned int rows;
unsigned int cols;
}Matrix;
+1 -1
View File
@@ -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);
+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)