From 3c49920613c589218775af6e52cd596f3314b3e4 Mon Sep 17 00:00:00 2001 From: Kristin Date: Thu, 13 Nov 2025 20:28:48 +0100 Subject: [PATCH] =?UTF-8?q?matrix.c=20und=20matrix.h,=20makefile=20f=C3=BC?= =?UTF-8?q?r=20windows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- makefile | 13 +++++++------ matrix.c | 58 +++++++++++++++++++++++++++++--------------------------- matrix.h | 18 +++++++++--------- 3 files changed, 46 insertions(+), 43 deletions(-) diff --git a/makefile b/makefile index f27b756..67a3c53 100644 --- a/makefile +++ b/makefile @@ -57,10 +57,11 @@ 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: -ifeq ($(OS),Windows_NT) - del /f *.o *.exe -else - rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests -endif - + rm -f *.o *.exe \ No newline at end of file diff --git a/matrix.c b/matrix.c index f1a06f3..6cd833e 100644 --- a/matrix.c +++ b/matrix.c @@ -1,36 +1,38 @@ +#include "matrix.h" #include #include -#include "matrix.h" - // TODO Matrix-Funktionen implementieren - -Matrix createMatrix(unsigned int rows, unsigned int cols) -{ - MatrixType* data = malloc(rows * cols * sizeof(MatrixType)); - Matrix newMatrix = {rows, cols, data}; - return newMatrix; +/*typedef struct { + unsigned int rows; //Zeilen + unsigned int cols; //Spalten + MatrixType *data; //Zeiger auf Speicherbereich Reihen*Spalten +} Matrix;*/ +Matrix createMatrix(unsigned int rows, unsigned int cols) { + MatrixType *data = + malloc(rows * cols * sizeof(MatrixType)); // Speicher reservieren, malloc + // liefert Zeiger auf Speicher + Matrix newMatrix = {rows, cols, data}; // neue Matrix nach struct + return newMatrix; } - -void clearMatrix(Matrix *matrix) -{ +void clearMatrix(Matrix *matrix) { + matrix->data = UNDEFINED_MATRIX_VALUE; + matrix->rows = UNDEFINED_MATRIX_VALUE; + matrix->cols = UNDEFINED_MATRIX_VALUE; + free((*matrix).data); // Speicher freigeben } - -void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) -{ - +void setMatrixAt(MatrixType value, Matrix matrix, + unsigned int rowIdx, // Kopie der Matrix wird übergeben + unsigned int colIdx) { + matrix.data[rowIdx * matrix.cols + colIdx] = + value; // rowIdx * matrix.cols -> Beginn der Zeile colIdx ->Spalte + // innerhalb der Zeile } - -MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) -{ - +MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, + unsigned int colIdx) { + return 0; } - -Matrix add(const Matrix matrix1, const Matrix matrix2) -{ - +Matrix add(const Matrix matrix1, const Matrix matrix2) { + // broadcasting + return matrix1; } - -Matrix multiply(const Matrix matrix1, const Matrix matrix2) -{ - -} \ No newline at end of file +Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; } diff --git a/matrix.h b/matrix.h index 736e6e1..1d37962 100644 --- a/matrix.h +++ b/matrix.h @@ -6,20 +6,20 @@ typedef float MatrixType; // TODO Matrixtyp definieren -typedef struct -{ - unsigned int rows; - unsigned int cols; - MatrixType *data; -} Matrix; +typedef struct { + unsigned int rows; + unsigned int cols; + MatrixType *data; +} Matrix; Matrix createMatrix(unsigned int rows, unsigned int cols); void clearMatrix(Matrix *matrix); -void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx); -MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx); +void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, + unsigned int colIdx); +MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, + unsigned int colIdx); Matrix add(const Matrix matrix1, const Matrix matrix2); Matrix multiply(const Matrix matrix1, const Matrix matrix2); - #endif