Add Funktion weiter geschrieben, todo: Broadcasting

This commit is contained in:
silvana884 2025-11-14 10:02:08 +01:00
parent 526ed2823f
commit 5de0e89bea

View File

@ -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
}
else if(rows1 == rows2 && cols1 == cols2) //Addition nur moeglich, wenn beide AMtrizen gleiche ANzahl an Zeilen und Spalten haben
if(rows1 == 1) //Wenn die erste Matrix der Vektor ist
{
Matrix addition = createMatrix(rows1, cols2);
return broadcasting(matrix1, matrix2);
}
else
{
return broadcasting(matrix2, matrix1);
}
}
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 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)
{