Started fixing matrixMultiply

This commit is contained in:
Lukas Weber 2025-11-23 22:23:45 +01:00
parent 6524bf95e4
commit c99db0f96c

View File

@ -108,10 +108,14 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
Matrix multiply(const Matrix matrix1, const Matrix matrix2) Matrix multiply(const Matrix matrix1, const Matrix matrix2)
{ {
Matrix result; Matrix result;
result.rows = 0;
result.cols = 0;
result.buffer = NULL;
if (matrix1.rows == matrix2.cols) {
result.rows = matrix1.rows; result.rows = matrix1.rows;
result.cols = matrix2.cols; result.cols = matrix2.cols;
if (matrix1.rows == matrix2.cols) { if (matrix1.cols == matrix2.rows) {
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType)); result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
@ -124,8 +128,6 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
result.buffer[i * matrix1.cols + j] = value; result.buffer[i * matrix1.cols + j] = value;
} }
} }
return result; }
}
printf("Die angegebenen Matrizen haben keine passenden Dimensionen für die Multiplikation");
return result; return result;
} }