first pass matrix add, ohne broadcasting
This commit is contained in:
parent
97df88c0ab
commit
7f3c6d1d3f
33
matrix.c
33
matrix.c
@ -41,25 +41,28 @@ MatrixType getMatrixAt(const Matrix matrix,
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2) {
|
Matrix add(const Matrix matrix1, const Matrix matrix2) {
|
||||||
|
|
||||||
// Ergebnismatrix
|
|
||||||
Matrix result;
|
Matrix result;
|
||||||
|
const int cols1 = matrix1.cols;
|
||||||
// Broadcasting nur bei Vektor und Matrix, Fehlermeldung bei zwei unpassender
|
const int rows1 = matrix1.rows;
|
||||||
// Matrix
|
const int cols2 = matrix2.cols;
|
||||||
if (matrix1.rows != matrix2.rows) {
|
const int rows2 = matrix2.rows;
|
||||||
|
const int colsEqu = (matrix1.cols == matrix2.cols) ? 1 : 0;
|
||||||
// check, which one is smaller
|
const int rowsEqu = (matrix1.rows == matrix2.rows) ? 1 : 0;
|
||||||
// realloc
|
if(colsEqu && rowsEqu)
|
||||||
|
{
|
||||||
|
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
|
||||||
|
for(int i = 0; i < rows1; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < cols1; j++)
|
||||||
|
{
|
||||||
|
int valueM1 = getMatrixAt(matrix1, i, j);
|
||||||
|
int valueM2 =getMatrixAt(matrix2, i, j);
|
||||||
|
int sum = valueM1 + valueM2;
|
||||||
|
setMatrixAt(sum, result,i,j);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matrix1.cols != matrix2.cols) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Speicher reservieren
|
|
||||||
|
|
||||||
// Matrix addieren
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; }
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user