broadcasting

This commit is contained in:
Max-R 2025-11-22 11:54:32 +01:00
parent e1ea9f33cd
commit 35a598a276

View File

@ -44,6 +44,27 @@ MatrixType getMatrixAt(const Matrix matrix,
return value; return value;
} }
Matrix broadcastingCols(const Matrix matrix, const unsigned int cols){
Matrix copy1 = createMatrix(matrix.rows, cols);
for (int r= 0; r < matrix.rows; r++){
MatrixType valueMatrix1 = getMatrixAt(matrix, r, 0);
for (int c=0; c < cols; c++){
setMatrixAt(valueMatrix1, copy1,r,c);
}
}
return copy1;
}
Matrix broadcastingRows(const Matrix matrix, const unsigned int rows){
Matrix copy1 = createMatrix(rows, matrix.cols);
for (int c= 0; c < matrix.cols; c++){
MatrixType valueMatrix1 = getMatrixAt(matrix, c, 0);
for (int r=0; r < rows; r++){
setMatrixAt(valueMatrix1, copy1,r,c);
}
}
return copy1;
}
Matrix add(const Matrix matrix1, const Matrix matrix2) { Matrix add(const Matrix matrix1, const Matrix matrix2) {
// Ergebnismatrix // Ergebnismatrix
@ -71,20 +92,33 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) {
} }
return result; return result;
} }
else if (rowsEqual ==1 && colsEqual == 0){ else if (rowsEqual ==1 && (cols1 ==1 || cols2 ==1)){
if (cols1==1){ //broadcasting von vektor 1 zu matrix 1, add
Matrix newMatrix = broadcastingCols(matrix1, cols2);
//add
}
else{
Matrix newMatrix2 = broadcastingCols(matrix1, cols1);
//add
}
} }
else if (rowsEqual == 0 && colsEqual == 1){
else if ((rows1 ==1 || rows2 ==1) && colsEqual == 1){
if (rows1==1){
Matrix newMatrix = broadcastingRows(matrix1, rows2);
//add
}
else{
Matrix newMatrix2 = broadcastingRows(matrix1, rows1);
//add
}
} }
else { else {
// kein add möglich
} }
// Speicher reservieren
// Matrix addieren
return result; return result;
} }