Compare commits

4 Commits
Author SHA1 Message Date
Simon May 06109225f8 debugged 2025-11-18 15:13:23 +01:00
hallerni98888 7837be1c3e done? 2025-11-14 17:25:07 +01:00
Simon 44f0bfc16d sync 2025-11-14 13:01:03 +01:00
Simon May ff21ecab21 nochmal? 2025-11-14 12:36:47 +01:00
5 changed files with 97 additions and 21 deletions
+33
View File
@@ -0,0 +1,33 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/mnist.exe",
"args": ["mnist_test.info2","mnist_model.info2"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\ucrt64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
+1 -1
View File
@@ -93,5 +93,5 @@ void clearSeries(GrayScaleImageSeries *series)
free(series->images); // Speicher für die Bild-Array freigeben free(series->images); // Speicher für die Bild-Array freigeben
free(series->labels); // Speicher für die Labels freigeben free(series->labels); // Speicher für die Labels freigeben
free(series); free(series); // Speicher freigeben
} }
+6 -18
View File
@@ -6,13 +6,13 @@
Matrix createMatrix(unsigned int rows, unsigned int cols) Matrix createMatrix(unsigned int rows, unsigned int cols)
{ {
Matrix m = {0, 0, NULL}; Matrix m = {NULL, 0, 0};
if (rows > 0 && cols > 0) if (rows > 0 && cols > 0)
{ {
m.buffer = malloc(rows * cols * sizeof(MatrixType));
m.rows = rows; m.rows = rows;
m.cols = cols; m.cols = cols;
m.buffer = malloc(rows * cols * sizeof(int));
} }
return m; return m;
@@ -65,23 +65,11 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
return result; return result;
} }
result.rows = matrix1.rows;
result.cols = matrix1.cols;
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
// wenn buffer nicht allokiert werden kann dann zurücksetzen und abbrechen
if (result.buffer == NULL)
{
result.rows = result.cols = 0;
return result;
}
if (matrix1.cols == 1 && matrix1.rows == matrix2.rows) // Broadcasting if (matrix1.cols == 1 && matrix1.rows == matrix2.rows) // Broadcasting
{ {
result.rows = matrix2.rows; result = createMatrix(matrix2.rows, matrix2.cols);
result.cols = matrix2.cols;
for (unsigned int i = 0; i < matrix1.rows; i++) for (unsigned int i = 0; i < matrix1.rows; i++)
{ {
for (unsigned int j = 0; j < result.cols; j++) for (unsigned int j = 0; j < result.cols; j++)
@@ -95,8 +83,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
else if (matrix2.cols == 1 && matrix1.rows == matrix2.rows) else if (matrix2.cols == 1 && matrix1.rows == matrix2.rows)
{ {
result.rows = matrix1.rows; result = createMatrix(matrix1.rows, matrix1.cols);
result.cols = matrix1.cols;
for (unsigned int i = 0; i < matrix2.rows; i++) for (unsigned int i = 0; i < matrix2.rows; i++)
{ {
@@ -109,6 +96,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
else else
{ {
result = createMatrix(matrix1.rows, matrix1.cols);
// Elementweise Addition // Elementweise Addition
for (unsigned int i = 0; i < result.rows; i++) for (unsigned int i = 0; i < result.rows; i++)
{ {
+1 -1
View File
@@ -9,9 +9,9 @@ typedef float MatrixType;
typedef struct typedef struct
{ {
MatrixType *buffer; // Zeiger auf die Matrixdaten
unsigned int rows; // Anzahl der Zeilen unsigned int rows; // Anzahl der Zeilen
unsigned int cols; // Anzahl der Spalten unsigned int cols; // Anzahl der Spalten
MatrixType *buffer; // Zeiger auf die Matrixdaten
} Matrix; } Matrix;
+56 -1
View File
@@ -8,7 +8,62 @@
static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn) static void prepareNeuralNetworkFile(const char *path, const NeuralNetwork nn)
{ {
// TODO FILE *file = fopen(path, "wb");
if (!file) {
perror("Fehler beim Erstellen der Testdatei");
exit(EXIT_FAILURE);
}
// File header
const char *fileTag = "__info2_neural_network_file_format__";
fwrite(fileTag, strlen(fileTag), 1, file);
if (nn.numberOfLayers == 0)
{
unsigned int zero = 0;
fwrite(&zero, sizeof(unsigned int), 1, file);
fclose(file);
return;
}
// first layer dimension
unsigned int in = nn.layers[0].weights.cols;
unsigned int out = nn.layers[0].weights.rows;
fwrite(&in, sizeof(unsigned int), 1, file);
fwrite(&out, sizeof(unsigned int), 1, file);
// do all layers
for (unsigned int i = 0; i < nn.numberOfLayers; i++)
{
const Layer *L = &nn.layers[i];
// Write weights matrix
fwrite(L->weights.buffer,
sizeof(MatrixType),
L->weights.rows * L->weights.cols,
file);
// Write biases matrix
fwrite(L->biases.buffer,
sizeof(MatrixType),
L->biases.rows * L->biases.cols,
file);
// After layer i, write dimension of next layer
if (i + 1 < nn.numberOfLayers)
{
unsigned int nextOut = nn.layers[i+1].weights.rows;
fwrite(&nextOut, sizeof(unsigned int), 1, file);
}
}
// --- 5. Write terminating zero ---
unsigned int zero = 0;
fwrite(&zero, sizeof(unsigned int), 1, file);
fclose(file);
} }
void test_loadModelReturnsCorrectNumberOfLayers(void) void test_loadModelReturnsCorrectNumberOfLayers(void)