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