From 06109225f8d108a421d27fbadcacfbe58b24a6b0 Mon Sep 17 00:00:00 2001 From: Simon May Date: Tue, 18 Nov 2025 15:13:23 +0100 Subject: [PATCH] debugged --- .vscode/launch.json | 33 +++++++++++++++++++++++++++++++++ matrix.c | 22 +++++----------------- 2 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4663dd2 --- /dev/null +++ b/.vscode/launch.json @@ -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 + } + ] + } + ] +} \ No newline at end of file diff --git a/matrix.c b/matrix.c index 85fc869..2b6f4a8 100644 --- a/matrix.c +++ b/matrix.c @@ -10,7 +10,7 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) if (rows > 0 && cols > 0) { - m.buffer = malloc(rows * cols * sizeof(int)); + m.buffer = malloc(rows * cols * sizeof(MatrixType)); m.rows = rows; m.cols = cols; } @@ -65,23 +65,11 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) 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 { - result.rows = matrix2.rows; - result.cols = matrix2.cols; - + result = createMatrix(matrix2.rows, matrix2.cols); + for (unsigned int i = 0; i < matrix1.rows; i++) { 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) { - result.rows = matrix1.rows; - result.cols = matrix1.cols; + result = createMatrix(matrix1.rows, matrix1.cols); for (unsigned int i = 0; i < matrix2.rows; i++) { @@ -109,6 +96,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) else { + result = createMatrix(matrix1.rows, matrix1.cols); // Elementweise Addition for (unsigned int i = 0; i < result.rows; i++) {