Compare commits

..

No commits in common. "8676389e6212f4098809478c76db9a6662bb4728" and "9bd9cd79853f026b7ca57a8187895d19c285eb3a" have entirely different histories.

2 changed files with 10 additions and 13 deletions

View File

@ -5,11 +5,11 @@
// TODO Matrix-Funktionen implementieren // TODO Matrix-Funktionen implementieren
typedef struct Matrix{ typedef struct Matrix {
unsigned int rows; unsigned int rows;
unsigned int cols; unsigned int cols;
MatrixType* buffer; MatrixType* buffer;
}Matrix; } Matrix;
Matrix createMatrix(unsigned int rows, unsigned int cols) Matrix createMatrix(unsigned int rows, unsigned int cols)
@ -31,10 +31,10 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
{ {
if (rowIdx >= matrix.rows || colIdx >= matrix.cols){ if (rowIdx >= matrix.rows || colIdx >= matrix.cols){
printf("Index out of bounds\n"); //Error Message because Index Input exceeds Matrix printf("Index out of bounds\n"); //Error Message because Index Input exceeds Matrix
} }
else{ else{
matrix.buffer[rowIdx * matrix.cols + colIdx] = value; //Writes Value of value variable in the selected place in Matrix matrix.buffer[rowIdx * matrix.cols + colIdx] = value; //Writes Value of value variable in the selected place in Matrix
} }
} }
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx) MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
@ -47,8 +47,8 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
MatrixType value = matrix.buffer[rowIdx * matrix.cols + colIdx]; //Stores value of selected place of Matrix in value variable MatrixType value = matrix.buffer[rowIdx * matrix.cols + colIdx]; //Stores value of selected place of Matrix in value variable
return value; return value;
}
} }
}
Matrix add(const Matrix matrix1, const Matrix matrix2) Matrix add(const Matrix matrix1, const Matrix matrix2)
{ {
@ -65,15 +65,16 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
//Adding Matrix Elements of same row and col index together and store in new Matrix //Adding Matrix Elements of same row and col index together and store in new Matrix
MatrixErgebnis.buffer[i * matrix1.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix1.cols + j]; MatrixErgebnis.buffer[i * matrix1.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix1.cols + j];
} }
} }
} }
return MatrixErgebnis; return MatrixErgebnis;
} }
Matrix multiply(const Matrix matrix1, const Matrix matrix2) Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{ {
Matrix result; Matrix result;
result.rows = matrix1.rows; result.rows = matrix1.rows;
result.cols = matrix2.cols; result.cols = matrix2.cols;

View File

@ -7,11 +7,7 @@ typedef float MatrixType;
// TODO Matrixtyp definieren // TODO Matrixtyp definieren
typedef struct Matrix{ typedef struct Matrix Matrix;
unsigned int rows;
unsigned int cols;
MatrixType* buffer;
}Matrix;