first pass matrix add, ohne broadcasting

This commit is contained in:
Tobias Kachel 2025-11-20 16:04:01 +01:00
parent 97df88c0ab
commit 7f3c6d1d3f

View File

@ -41,25 +41,28 @@ MatrixType getMatrixAt(const Matrix matrix,
return value; return value;
} }
Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix add(const Matrix matrix1, const Matrix matrix2) {
// Ergebnismatrix
Matrix result; Matrix result;
const int cols1 = matrix1.cols;
// Broadcasting nur bei Vektor und Matrix, Fehlermeldung bei zwei unpassender const int rows1 = matrix1.rows;
// Matrix const int cols2 = matrix2.cols;
if (matrix1.rows != matrix2.rows) { const int rows2 = matrix2.rows;
const int colsEqu = (matrix1.cols == matrix2.cols) ? 1 : 0;
// check, which one is smaller const int rowsEqu = (matrix1.rows == matrix2.rows) ? 1 : 0;
// realloc if(colsEqu && rowsEqu)
{
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);
} }
if (matrix1.cols != matrix2.cols) {
} }
// Speicher reservieren
// Matrix addieren
return result; return result;
}
} }
Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; } Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; }