diff --git a/matrix.c b/matrix.c index e81551c..1cb0241 100644 --- a/matrix.c +++ b/matrix.c @@ -42,14 +42,22 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) cols2 = matrix2->cols; if((rows1 == 1 || rows2 == 1) && cols1 == cols2) //Broadcasting { - //TODO: Broadcasting + if(rows1 == 1) //Wenn die erste Matrix der Vektor ist + { + return broadcasting(matrix1, matrix2); + } + else + { + return broadcasting(matrix2, matrix1); + } } - else if(rows1 == rows2 && cols1 == cols2) //Addition nur moeglich, wenn beide AMtrizen gleiche ANzahl an Zeilen und Spalten haben + else if(rows1 == rows2 && cols1 == cols2) //Addition nur moeglich, wenn beide Matrizen gleiche ANzahl an Zeilen und Spalten haben { - Matrix addition = createMatrix(rows1, cols2); + Matrix addition = createMatrix(rows1, cols2); //Matrix erstellt, in die die addierten Werte geschrieben werden MatrixType wert1; MatrixType wert2; - for(int i = 0; i < rows; i++){ + int anzahl = rows1 * cols1; + for(int i = 0; i < anzahl; i++){ //soll fuer jedes Element durchlaufen, sodass alle Werte von beiden Matrizen aufaddiert werden wert1 = getMatrixAt(matrix1, rows1, cols1); wert2 = getMatrixAt(matrix2, rows2, cols2); MatrixType addierterWert = wert1 + wert2; @@ -61,6 +69,20 @@ Matrix add(const Matrix matrix1, const Matrix matrix2) } } +Matrix broadcasting(const Matrix vektor, const Matrix matrix) + { + int rows = matrix->rows; + int cols = matrix->cols; + Matrix result = createMatrix(rows, cols); + MatrixType wert; + MatrixType koordinate; + for(int i = 0; i < (rows*cols); i++) + { + wert = getMatrixAt(matrix, rows, cols); + koordinate = + } + } + Matrix multiply(const Matrix matrix1, const Matrix matrix2) {