From 0e3f03a03d1ecd7687cc94c91c83ff691df74775 Mon Sep 17 00:00:00 2001 From: Max-R Date: Tue, 11 Nov 2025 09:20:40 +0100 Subject: [PATCH 01/14] Matrix definiert --- .vscode/c_cpp_properties.json | 18 +++++++++++ .vscode/launch.json | 24 ++++++++++++++ .vscode/settings.json | 59 +++++++++++++++++++++++++++++++++++ matrix.h | 6 +++- 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..cb8d469 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,18 @@ +{ + "configurations": [ + { + "name": "windows-gcc-x64", + "includePath": [ + "${workspaceFolder}/**" + ], + "compilerPath": "C:/ProgramData/mingw64/mingw64/bin/gcc.exe", + "cStandard": "${default}", + "cppStandard": "${default}", + "intelliSenseMode": "windows-gcc-x64", + "compilerArgs": [ + "" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7583c69 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "C/C++ Runner: Debug Session", + "type": "cppdbg", + "request": "launch", + "args": [], + "stopAtEntry": false, + "externalConsole": true, + "cwd": "c:/Users/Max-R/I2Pr/repoKachelto/I2-Pr_neuronalesNetz/info2Praktikum-NeuronalesNetz", + "program": "c:/Users/Max-R/I2Pr/repoKachelto/I2-Pr_neuronalesNetz/info2Praktikum-NeuronalesNetz/build/Debug/outDebug", + "MIMode": "gdb", + "miDebuggerPath": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..bb879da --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,59 @@ +{ + "C_Cpp_Runner.cCompilerPath": "gcc", + "C_Cpp_Runner.cppCompilerPath": "g++", + "C_Cpp_Runner.debuggerPath": "gdb", + "C_Cpp_Runner.cStandard": "", + "C_Cpp_Runner.cppStandard": "", + "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.useMsvc": false, + "C_Cpp_Runner.warnings": [ + "-Wall", + "-Wextra", + "-Wpedantic", + "-Wshadow", + "-Wformat=2", + "-Wcast-align", + "-Wconversion", + "-Wsign-conversion", + "-Wnull-dereference" + ], + "C_Cpp_Runner.msvcWarnings": [ + "/W4", + "/permissive-", + "/w14242", + "/w14287", + "/w14296", + "/w14311", + "/w14826", + "/w44062", + "/w44242", + "/w14905", + "/w14906", + "/w14263", + "/w44265", + "/w14928" + ], + "C_Cpp_Runner.enableWarnings": true, + "C_Cpp_Runner.warningsAsError": false, + "C_Cpp_Runner.compilerArgs": [], + "C_Cpp_Runner.linkerArgs": [], + "C_Cpp_Runner.includePaths": [], + "C_Cpp_Runner.includeSearch": [ + "*", + "**/*" + ], + "C_Cpp_Runner.excludeSearch": [ + "**/build", + "**/build/**", + "**/.*", + "**/.*/**", + "**/.vscode", + "**/.vscode/**" + ], + "C_Cpp_Runner.useAddressSanitizer": false, + "C_Cpp_Runner.useUndefinedSanitizer": false, + "C_Cpp_Runner.useLeakSanitizer": false, + "C_Cpp_Runner.showCompilationTime": false, + "C_Cpp_Runner.useLinkTimeOptimization": false, + "C_Cpp_Runner.msvcSecureNoWarnings": false +} \ No newline at end of file diff --git a/matrix.h b/matrix.h index cc640d1..3e1b911 100644 --- a/matrix.h +++ b/matrix.h @@ -6,7 +6,11 @@ typedef float MatrixType; // TODO Matrixtyp definieren - +typedef struct{ + unsigned int rows; + unsigned int cols; + MatrixType *data; //Zeiger auf Speicher (Reihen*Spalten) +} Matrix; Matrix createMatrix(unsigned int rows, unsigned int cols); void clearMatrix(Matrix *matrix); From ec54bdd9513f229a69244b3da43d80b0c0a5f535 Mon Sep 17 00:00:00 2001 From: Max-R Date: Tue, 11 Nov 2025 10:36:11 +0100 Subject: [PATCH 02/14] =?UTF-8?q?create=20Matrix=20gef=C3=BCllt,=20test=20?= =?UTF-8?q?unit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- imageInputTests.c | 4 ++-- matrix.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/imageInputTests.c b/imageInputTests.c index c704271..03240ab 100644 --- a/imageInputTests.c +++ b/imageInputTests.c @@ -54,7 +54,7 @@ void test_readImagesReturnsCorrectImageWidth(void) GrayScaleImageSeries *series = NULL; const unsigned short expectedWidth = 10; const char *path = "testFile.info2"; - prepareImageFile(path, 8, expectedWidth, 2, 1); + prepareImageFile(path, expectedWidth, 8, 2, 1); series = readImages(path); TEST_ASSERT_NOT_NULL(series); TEST_ASSERT_NOT_NULL(series->images); @@ -70,7 +70,7 @@ void test_readImagesReturnsCorrectImageHeight(void) GrayScaleImageSeries *series = NULL; const unsigned short expectedHeight = 10; const char *path = "testFile.info2"; - prepareImageFile(path, expectedHeight, 8, 2, 1); + prepareImageFile(path, 8, expectedHeight, 2, 1); series = readImages(path); TEST_ASSERT_NOT_NULL(series); TEST_ASSERT_NOT_NULL(series->images); diff --git a/matrix.c b/matrix.c index ad00628..66a3b4a 100644 --- a/matrix.c +++ b/matrix.c @@ -6,7 +6,9 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { - + MatrixType*data= malloc(rows*cols*sizeof(MatrixType)); + Matrix newMatrix = {rows,cols,data}; + return newMatrix; } void clearMatrix(Matrix *matrix) From 3de79e2b83420a26b3a7ad0c1f6648623e4f5190 Mon Sep 17 00:00:00 2001 From: Max-R Date: Tue, 11 Nov 2025 11:05:28 +0100 Subject: [PATCH 03/14] =?UTF-8?q?clearMatrix=20f=C3=BCllen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matrix.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/matrix.c b/matrix.c index 66a3b4a..ac8c915 100644 --- a/matrix.c +++ b/matrix.c @@ -6,13 +6,18 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) { - MatrixType*data= malloc(rows*cols*sizeof(MatrixType)); + MatrixType*data= malloc(rows*cols*sizeof(MatrixType)); //Speicher reservieren Matrix newMatrix = {rows,cols,data}; return newMatrix; } void clearMatrix(Matrix *matrix) { + matrix->data = UNDEFINED_MATRIX_VALUE; //Auf 0 setzen + matrix->rows = UNDEFINED_MATRIX_VALUE; + matrix->cols = UNDEFINED_MATRIX_VALUE; + + free((*matrix).data); //Speicher freigeben } From 0886489d4942d994fe8d0aa0f7b700090a5aa48a Mon Sep 17 00:00:00 2001 From: Max-R Date: Thu, 20 Nov 2025 16:03:44 +0100 Subject: [PATCH 04/14] Matrix noch ohne broadcasting --- matrix.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/matrix.c b/matrix.c index 7a8dcac..fb44123 100644 --- a/matrix.c +++ b/matrix.c @@ -44,16 +44,38 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { // Ergebnismatrix Matrix result; + const int cols1 = matrix1.cols; + const int rows1 = matrix1.rows; + const int cols2 = matrix2.cols; + const int rows2 = matrix2.rows; + + const int rowsEqual = (matrix1.rows==matrix2.rows) ? 1: 0; + const int colsEqual = (matrix1.cols==matrix2.cols) ? 1: 0; + // Broadcasting nur bei Vektor und Matrix, Fehlermeldung bei zwei unpassender // Matrix - if (matrix1.rows != matrix2.rows) { - - // check, which one is smaller - // realloc + if (rowsEqual == 1 && colsEqual == 1){ + Matrix result = createMatrix(matrix1.rows, matrix1.cols); + for (int i = 0; i< rows1; i++) { + for (int j= 0; j< cols1; j++){ + int valueM1= getMatrixAt(matrix1, i, j); + int valueM2= getMatrixAt(matrix2, i, j); + int sum = valueM1 + valueM2; + setMatrixAt(sum, result, i, j); + } + } + return result; } + else if (rowsEqual ==1 && colsEqual == 0){ + + } + else if (rowsEqual == 0 && colsEqual == 1){ + + } + else { + - if (matrix1.cols != matrix2.cols) { } // Speicher reservieren From e1ea9f33cd9ac7d4521cefe6fc6825732101d1ee Mon Sep 17 00:00:00 2001 From: Max-R Date: Sat, 22 Nov 2025 10:55:27 +0100 Subject: [PATCH 05/14] create matrix mit null --- makefile | 14 ++++++-------- matrix.c | 4 ++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/makefile b/makefile index 5d94684..444bd21 100644 --- a/makefile +++ b/makefile @@ -57,12 +57,10 @@ imageInputTests: imageInput.o imageInputTests.c $(unityfolder)/unity.c # -------------------------- # Clean # -------------------------- -#clean: -#ifeq ($(OS),Windows_NT) -# del /f *.o *.exe -#else -# rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests -#endif -# clean für windows clean: - rm -f *.o *.exe \ No newline at end of file +ifeq ($(OS),Windows_NT) + del /f *.o *.exe +else + rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests +endif + \ No newline at end of file diff --git a/matrix.c b/matrix.c index fb44123..da73deb 100644 --- a/matrix.c +++ b/matrix.c @@ -8,6 +8,10 @@ MatrixType *buffer; //Zeiger auf Speicherbereich Reihen*Spalten } Matrix;*/ Matrix createMatrix(unsigned int rows, unsigned int cols) { + if (cols == 0 || rows == 0){ + Matrix errorMatrix = {0, 0, NULL}; + return errorMatrix; + } MatrixType *buffer = malloc(rows * cols * sizeof(MatrixType)); // Speicher reservieren, malloc // liefert Zeiger auf Speicher From 35a598a2769ca0e862a070e9e73fc8c8052f25e6 Mon Sep 17 00:00:00 2001 From: Max-R Date: Sat, 22 Nov 2025 11:54:32 +0100 Subject: [PATCH 06/14] broadcasting --- matrix.c | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/matrix.c b/matrix.c index da73deb..5f75d77 100644 --- a/matrix.c +++ b/matrix.c @@ -44,6 +44,27 @@ MatrixType getMatrixAt(const Matrix matrix, return value; } +Matrix broadcastingCols(const Matrix matrix, const unsigned int cols){ + Matrix copy1 = createMatrix(matrix.rows, cols); + for (int r= 0; r < matrix.rows; r++){ + MatrixType valueMatrix1 = getMatrixAt(matrix, r, 0); + for (int c=0; c < cols; c++){ + setMatrixAt(valueMatrix1, copy1,r,c); + } + } + return copy1; +} +Matrix broadcastingRows(const Matrix matrix, const unsigned int rows){ + Matrix copy1 = createMatrix(rows, matrix.cols); + for (int c= 0; c < matrix.cols; c++){ + MatrixType valueMatrix1 = getMatrixAt(matrix, c, 0); + for (int r=0; r < rows; r++){ + setMatrixAt(valueMatrix1, copy1,r,c); + } + } + return copy1; + +} Matrix add(const Matrix matrix1, const Matrix matrix2) { // Ergebnismatrix @@ -71,20 +92,33 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { } return result; } - else if (rowsEqual ==1 && colsEqual == 0){ - + else if (rowsEqual ==1 && (cols1 ==1 || cols2 ==1)){ + if (cols1==1){ //broadcasting von vektor 1 zu matrix 1, add + Matrix newMatrix = broadcastingCols(matrix1, cols2); + //add + } + else{ + Matrix newMatrix2 = broadcastingCols(matrix1, cols1); + //add + } } - else if (rowsEqual == 0 && colsEqual == 1){ + else if ((rows1 ==1 || rows2 ==1) && colsEqual == 1){ + if (rows1==1){ + Matrix newMatrix = broadcastingRows(matrix1, rows2); + //add + } + else{ + Matrix newMatrix2 = broadcastingRows(matrix1, rows1); + //add + } } else { - + // kein add möglich } - // Speicher reservieren - - // Matrix addieren + return result; } From 4e2ee7078a539a086ffe96b6cb540898147f079b Mon Sep 17 00:00:00 2001 From: Max-R Date: Sat, 22 Nov 2025 12:41:46 +0100 Subject: [PATCH 07/14] alles bis uf multiply --- matrix.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/matrix.c b/matrix.c index 5f75d77..d3987b5 100644 --- a/matrix.c +++ b/matrix.c @@ -28,9 +28,13 @@ void setMatrixAt(const MatrixType value, Matrix matrix, const unsigned int rowIdx, // Kopie der Matrix wird übergeben const unsigned int colIdx) { - matrix.buffer[rowIdx * matrix.cols + colIdx] = - value; // rowIdx * matrix.cols -> Beginn der Zeile colIdx ->Spalte - // innerhalb der Zeile + if (rowIdx >= matrix.rows || colIdx >= matrix.cols) { + // Speichergröße nicht überschreiten + return; + } + matrix.buffer[rowIdx * matrix.cols + colIdx] = value; + // rowIdx * matrix.cols -> Beginn der Zeile colIdx ->Spalte + // innerhalb der Zeile } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, // Kopie der Matrix wird übergeben @@ -57,7 +61,7 @@ Matrix broadcastingCols(const Matrix matrix, const unsigned int cols){ Matrix broadcastingRows(const Matrix matrix, const unsigned int rows){ Matrix copy1 = createMatrix(rows, matrix.cols); for (int c= 0; c < matrix.cols; c++){ - MatrixType valueMatrix1 = getMatrixAt(matrix, c, 0); + MatrixType valueMatrix1 = getMatrixAt(matrix, 0, c); for (int r=0; r < rows; r++){ setMatrixAt(valueMatrix1, copy1,r,c); } @@ -96,10 +100,30 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { if (cols1==1){ //broadcasting von vektor 1 zu matrix 1, add Matrix newMatrix = broadcastingCols(matrix1, cols2); //add + Matrix result = createMatrix(newMatrix.rows, newMatrix.cols); + for (int i = 0; i< rows1; i++) { + for (int j= 0; j< cols2; j++){ + int valueM1= getMatrixAt(newMatrix, i, j); + int valueM2= getMatrixAt(matrix2, i, j); + int sum = valueM1 + valueM2; + setMatrixAt(sum, result, i, j); + } + } + return result; } else{ - Matrix newMatrix2 = broadcastingCols(matrix1, cols1); + Matrix newMatrix2 = broadcastingCols(matrix2, cols1); //add + Matrix result = createMatrix(newMatrix2.rows, newMatrix2.cols); + for (int i = 0; i< rows1; i++) { + for (int j= 0; j< cols1; j++){ + int valueM1= getMatrixAt(matrix1, i, j); + int valueM2= getMatrixAt(newMatrix2, i, j); + int sum = valueM1 + valueM2; + setMatrixAt(sum, result, i, j); + } + } + return result; } } @@ -107,15 +131,36 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { if (rows1==1){ Matrix newMatrix = broadcastingRows(matrix1, rows2); //add + Matrix result = createMatrix(newMatrix.rows, newMatrix.cols); + for (int i = 0; i< rows2; i++) { + for (int j= 0; j< cols1; j++){ + int valueM1= getMatrixAt(newMatrix, i, j); + int valueM2= getMatrixAt(matrix2, i, j); + int sum = valueM1 + valueM2; + setMatrixAt(sum, result, i, j); + } + } + return result; } else{ - Matrix newMatrix2 = broadcastingRows(matrix1, rows1); + Matrix newMatrix2 = broadcastingRows(matrix2, rows1); //add + Matrix result = createMatrix(newMatrix2.rows, newMatrix2.cols); + for (int i = 0; i< rows1; i++) { + for (int j= 0; j< cols1; j++){ + int valueM1= getMatrixAt(matrix1, i, j); + int valueM2= getMatrixAt(newMatrix2, i, j); + int sum = valueM1 + valueM2; + setMatrixAt(sum, result, i, j); + } + } + return result; } } else { // kein add möglich - + Matrix errorMatrix = {0, 0, NULL}; + return errorMatrix; } From b187a13b1721d57ab05d88c346bb470de3f9ac57 Mon Sep 17 00:00:00 2001 From: Max-R Date: Sat, 22 Nov 2025 15:17:12 +0100 Subject: [PATCH 08/14] multiply, besteht MatrixTests --- matrix.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/matrix.c b/matrix.c index d3987b5..e1da69d 100644 --- a/matrix.c +++ b/matrix.c @@ -162,9 +162,27 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix errorMatrix = {0, 0, NULL}; return errorMatrix; } - - - return result; } -Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; } +Matrix multiply(const Matrix matrix1, const Matrix matrix2) { + //Spalten1 müssen gleich zeilen2 sein! dann multiplizieren + if (matrix1.cols == matrix2.rows){ + Matrix multMatrix = createMatrix(matrix1.rows,matrix2.cols); + for (int r=0; r< matrix1.rows; r++){ + for (int c=0; c< matrix2.cols; c++){ + MatrixType sum = 0.0; + for (int k=0; k< matrix1.cols; k++){ + sum+= matrix1.buffer[r*matrix1.cols+k]*matrix2.buffer[k*matrix2.cols+c]; + } + multMatrix.buffer[r*multMatrix.cols+c] = sum; + } + } + return multMatrix; + } + //sonst fehler + else{ + Matrix errorMatrix = {0, 0, NULL}; + return errorMatrix; + } + //return matrix1; +} From 5075c3498335f25fdc06dc4fa0a4c1f015936c01 Mon Sep 17 00:00:00 2001 From: Max-R Date: Sat, 22 Nov 2025 15:19:41 +0100 Subject: [PATCH 09/14] kommentaare update --- matrix.c | 1 - 1 file changed, 1 deletion(-) diff --git a/matrix.c b/matrix.c index e1da69d..0d32065 100644 --- a/matrix.c +++ b/matrix.c @@ -184,5 +184,4 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) { Matrix errorMatrix = {0, 0, NULL}; return errorMatrix; } - //return matrix1; } From e7930c7eb0c2f6476d350d3349064bd9f5150a24 Mon Sep 17 00:00:00 2001 From: Max-R Date: Sat, 22 Nov 2025 15:23:50 +0100 Subject: [PATCH 10/14] kommentaare update --- matrix.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/matrix.c b/matrix.c index 0d32065..bb1dd8e 100644 --- a/matrix.c +++ b/matrix.c @@ -168,18 +168,21 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) { //Spalten1 müssen gleich zeilen2 sein! dann multiplizieren if (matrix1.cols == matrix2.rows){ Matrix multMatrix = createMatrix(matrix1.rows,matrix2.cols); + //durch neue matrix iterieren for (int r=0; r< matrix1.rows; r++){ for (int c=0; c< matrix2.cols; c++){ MatrixType sum = 0.0; + //skalarprodukte berechnen, k damit die ganze zeile mal die ganze spalte genommen wird quasi for (int k=0; k< matrix1.cols; k++){ sum+= matrix1.buffer[r*matrix1.cols+k]*matrix2.buffer[k*matrix2.cols+c]; } + //Ergebnisse in neue matrix speichern multMatrix.buffer[r*multMatrix.cols+c] = sum; } } return multMatrix; } - //sonst fehler + //sonst fehler, kein multiply möglich else{ Matrix errorMatrix = {0, 0, NULL}; return errorMatrix; From 21d9b5c01d41c418b5b8c2959f2a9ea8a64088c4 Mon Sep 17 00:00:00 2001 From: Max-R Date: Sat, 22 Nov 2025 15:29:32 +0100 Subject: [PATCH 11/14] =?UTF-8?q?so=20finde=20ich=20es=20sch=C3=B6ner...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- matrix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/matrix.c b/matrix.c index bb1dd8e..2a4eb7b 100644 --- a/matrix.c +++ b/matrix.c @@ -174,10 +174,11 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) { MatrixType sum = 0.0; //skalarprodukte berechnen, k damit die ganze zeile mal die ganze spalte genommen wird quasi for (int k=0; k< matrix1.cols; k++){ - sum+= matrix1.buffer[r*matrix1.cols+k]*matrix2.buffer[k*matrix2.cols+c]; + //sum+= matrix1.buffer[r*matrix1.cols+k]*matrix2.buffer[k*matrix2.cols+c]; + sum += getMatrixAt(matrix1, r, k)*getMatrixAt(matrix2, k, c); } //Ergebnisse in neue matrix speichern - multMatrix.buffer[r*multMatrix.cols+c] = sum; + setMatrixAt(sum, multMatrix, r, c); } } return multMatrix; From 98dd7896804b82ae9588acecad6c1f50c61ae2f7 Mon Sep 17 00:00:00 2001 From: kachelto100370 Date: Tue, 25 Nov 2025 09:10:54 +0100 Subject: [PATCH 12/14] input image things --- imageInput.c | 1 - 1 file changed, 1 deletion(-) diff --git a/imageInput.c b/imageInput.c index d31a7da..a72eda2 100644 --- a/imageInput.c +++ b/imageInput.c @@ -18,7 +18,6 @@ GrayScaleImageSeries *readImages(const char *path) GrayScaleImageSeries *series = NULL; FILE *file = fopen("mnist_test.info2","rb"); char headOfFile; - series = malloc(); return series; } From 0baf646832e80900554493ca7bbe90ac7b1a674b Mon Sep 17 00:00:00 2001 From: Max-R Date: Tue, 25 Nov 2025 09:57:28 +0100 Subject: [PATCH 13/14] add files to gitignore --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4f907f8..15d0ea4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ mnist runTests *.o -*.exe \ No newline at end of file +*.exe +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/settings.json From efa260ccbe1991f8ccb60fcfcd55033b84057c43 Mon Sep 17 00:00:00 2001 From: Max-R Date: Tue, 25 Nov 2025 10:15:52 +0100 Subject: [PATCH 14/14] 0 fehler bei add abfangen --- matrix.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/matrix.c b/matrix.c index 2a4eb7b..22b68f3 100644 --- a/matrix.c +++ b/matrix.c @@ -86,6 +86,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { // Matrix if (rowsEqual == 1 && colsEqual == 1){ Matrix result = createMatrix(matrix1.rows, matrix1.cols); + if (result.buffer == NULL){ + return (Matrix){0,0,NULL}; + } for (int i = 0; i< rows1; i++) { for (int j= 0; j< cols1; j++){ int valueM1= getMatrixAt(matrix1, i, j); @@ -101,6 +104,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix newMatrix = broadcastingCols(matrix1, cols2); //add Matrix result = createMatrix(newMatrix.rows, newMatrix.cols); + if (result.buffer == NULL){ + return (Matrix){0,0,NULL}; + } for (int i = 0; i< rows1; i++) { for (int j= 0; j< cols2; j++){ int valueM1= getMatrixAt(newMatrix, i, j); @@ -115,6 +121,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix newMatrix2 = broadcastingCols(matrix2, cols1); //add Matrix result = createMatrix(newMatrix2.rows, newMatrix2.cols); + if (result.buffer == NULL){ + return (Matrix){0,0,NULL}; + } for (int i = 0; i< rows1; i++) { for (int j= 0; j< cols1; j++){ int valueM1= getMatrixAt(matrix1, i, j); @@ -132,6 +141,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix newMatrix = broadcastingRows(matrix1, rows2); //add Matrix result = createMatrix(newMatrix.rows, newMatrix.cols); + if (result.buffer == NULL){ + return (Matrix){0,0,NULL}; + } for (int i = 0; i< rows2; i++) { for (int j= 0; j< cols1; j++){ int valueM1= getMatrixAt(newMatrix, i, j); @@ -146,6 +158,9 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix newMatrix2 = broadcastingRows(matrix2, rows1); //add Matrix result = createMatrix(newMatrix2.rows, newMatrix2.cols); + if (result.buffer == NULL){ + return (Matrix){0,0,NULL}; + } for (int i = 0; i< rows1; i++) { for (int j= 0; j< cols1; j++){ int valueM1= getMatrixAt(matrix1, i, j);