From bb87d30e056ca91ea81f993e7630cf154ba1d46b Mon Sep 17 00:00:00 2001 From: Laila Date: Mon, 10 Nov 2025 13:43:55 +0100 Subject: [PATCH] =?UTF-8?q?matrix.data=20zu=20matrix.buffer=20umgenannt,?= =?UTF-8?q?=20da=20Tests=20diese=20Bezeichnung=20erwarten.=20Test=20f?= =?UTF-8?q?=C3=BCr=20get,=20set=20und=20multiply=20laufen=20PASS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- info2praktikum-neuronalesnetz/matrix.c | 22 +++++++++++----------- info2praktikum-neuronalesnetz/matrix.h | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/info2praktikum-neuronalesnetz/matrix.c b/info2praktikum-neuronalesnetz/matrix.c index 16688c5..6e38675 100644 --- a/info2praktikum-neuronalesnetz/matrix.c +++ b/info2praktikum-neuronalesnetz/matrix.c @@ -10,8 +10,8 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) Matrix matrix; matrix.rows = rows; matrix.cols = cols; - matrix.data = (float *)malloc(rows * cols * sizeof(MatrixType)); - if (matrix.data != NULL) { + matrix.buffer = (float *)malloc(rows * cols * sizeof(MatrixType)); + if (matrix.buffer != NULL) { } return matrix; @@ -19,20 +19,20 @@ Matrix createMatrix(unsigned int rows, unsigned int cols) void clearMatrix(Matrix *matrix) { - if (matrix->data != NULL) { - free(matrix->data); - matrix->data = NULL; + if (matrix->buffer != NULL) { + free(matrix->buffer); + matrix->buffer = NULL; } } -void setMatrixAt(MatrixType value, Matrix* matrix, unsigned int rowIdx, unsigned int colIdx) +void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) { - if(rowIdx >= matrix->rows || colIdx >= matrix->cols){ + if(rowIdx >= matrix.rows || colIdx >= matrix.cols){ return; } - matrix->data[rowIdx * matrix->cols + colIdx] = value; + matrix.buffer[rowIdx * matrix.cols + colIdx] = value; } MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) @@ -41,7 +41,7 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co return 0; } MatrixType value; - value = matrix.data[rowIdx * matrix.cols + colIdx]; + value = matrix.buffer[rowIdx * matrix.cols + colIdx]; return value; } @@ -54,7 +54,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) { if (matrix1.cols != matrix2.rows){ Matrix errorMatrix = createMatrix(0, 0); - errorMatrix.data = NULL; + errorMatrix.buffer = NULL; return errorMatrix; } Matrix matrix3 = createMatrix(matrix1.rows, matrix2.cols); @@ -65,7 +65,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2) for(size_t k = 0; k < matrix1.cols; k++){ sum += getMatrixAt(matrix1, i, k) * getMatrixAt(matrix2, k, j); } - setMatrixAt(sum, &matrix3, i, j); + setMatrixAt(sum, matrix3, i, j); } } diff --git a/info2praktikum-neuronalesnetz/matrix.h b/info2praktikum-neuronalesnetz/matrix.h index 0598348..8c75533 100644 --- a/info2praktikum-neuronalesnetz/matrix.h +++ b/info2praktikum-neuronalesnetz/matrix.h @@ -6,7 +6,7 @@ typedef struct{ size_t rows; size_t cols; - float* data; + float* buffer; } Matrix;