weitere Absicherung multiply
This commit is contained in:
parent
75dc5fc631
commit
89262e4763
12
matrix.c
12
matrix.c
@ -32,7 +32,7 @@ void clearMatrix(Matrix *matrix)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx) //Problematisch Call-by-Value --> Call-by-Pointer
|
||||||
// Matrix matrix zu Matrix *matrix, empfehlung
|
// Matrix matrix zu Matrix *matrix, empfehlung
|
||||||
{
|
{
|
||||||
if (rowIdx < matrix.rows && colIdx < matrix.cols && matrix.buffer != NULL)
|
if (rowIdx < matrix.rows && colIdx < matrix.cols && matrix.buffer != NULL)
|
||||||
@ -102,11 +102,13 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
{
|
{
|
||||||
// Needed: rows/Zeilen, collums/Spalten
|
// Needed: rows/Zeilen, collums/Spalten
|
||||||
MatrixType buffer_add;
|
MatrixType buffer_add;
|
||||||
// Probe ob Spalten1 = Zeilen2
|
|
||||||
if (matrix1.cols != matrix2.rows)
|
if (!matrix1.buffer || !matrix2.buffer) // Probe ob leere Matrize vorliegt
|
||||||
|
return createMatrix(0, 0);
|
||||||
|
if (matrix1.cols != matrix2.rows) // Probe ob Spalten1 = Zeilen2
|
||||||
return createMatrix(0, 0);
|
return createMatrix(0, 0);
|
||||||
|
|
||||||
Matrix result_mul = createMatrix(matrix1.rows, matrix2.cols); // ""
|
Matrix result_mul = createMatrix(matrix1.rows, matrix2.cols);
|
||||||
|
|
||||||
for (unsigned int index = 0; index < matrix1.rows; index++)
|
for (unsigned int index = 0; index < matrix1.rows; index++)
|
||||||
{
|
{
|
||||||
@ -119,7 +121,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
buffer_add += getMatrixAt(matrix1, index, skalar) * getMatrixAt(matrix2, skalar, shift);
|
buffer_add += getMatrixAt(matrix1, index, skalar) * getMatrixAt(matrix2, skalar, shift);
|
||||||
}
|
}
|
||||||
// matrix_mul[index][shift] = buffer_add;
|
// matrix_mul[index][shift] = buffer_add;
|
||||||
setMatrixAt(buffer_add, result_mul, index, shift); // result als Pointer, also mit &result
|
setMatrixAt(buffer_add, result_mul, index, shift);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result_mul;
|
return result_mul;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user