forked from freudenreichan/info2Praktikum-NeuronalesNetz
broadcasting
This commit is contained in:
parent
e1ea9f33cd
commit
35a598a276
48
matrix.c
48
matrix.c
@ -44,6 +44,27 @@ MatrixType getMatrixAt(const Matrix matrix,
|
||||
|
||||
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) {
|
||||
|
||||
// Ergebnismatrix
|
||||
@ -71,20 +92,33 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) {
|
||||
}
|
||||
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 {
|
||||
|
||||
// kein add möglich
|
||||
|
||||
}
|
||||
|
||||
// Speicher reservieren
|
||||
|
||||
// Matrix addieren
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user