forked from freudenreichan/info2Praktikum-NeuronalesNetz
multiply fertig
This commit is contained in:
1 parent
c0f73f9362
commit
ebe3304c54
1 file changed
+19
-6
+19
-6
@@ -65,6 +65,10 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
if(matrix1.rows == matrix2.rows && matrix1.cols == matrix2.cols) {
|
||||
Matrix resultMatrix = createMatrix(matrix1.rows, matrix1.cols);
|
||||
|
||||
if (resultMatrix.buffer == NULL) {
|
||||
return resultMatrix;
|
||||
}
|
||||
for (unsigned int i = 0; i < matrix1.rows*matrix1.cols; i++) {
|
||||
resultMatrix.buffer[i]=matrix1.buffer[i]+matrix2.buffer[i];
|
||||
}
|
||||
@@ -76,21 +80,30 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
|
||||
if (matrix2.cols == 1) {
|
||||
resultMatrix = createMatrix(matrix1.rows, matrix1.cols);
|
||||
for (unsigned int i = 0; i < matrix1.rows*matrix1.cols; i++) {
|
||||
unsigned int rowIdx = i / matrix1.cols;
|
||||
resultMatrix.buffer[i] = matrix1.buffer[i] + matrix2.buffer[rowIdx];
|
||||
|
||||
if (resultMatrix.buffer == NULL) {
|
||||
return resultMatrix;
|
||||
}
|
||||
for (unsigned int i = 0; i < matrix1.rows*matrix1.cols; i++) {
|
||||
unsigned int rowIdx = i / matrix1.cols;
|
||||
resultMatrix.buffer[i] = matrix1.buffer[i] + matrix2.buffer[rowIdx];
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
resultMatrix = createMatrix(matrix2.rows, matrix2.cols);
|
||||
|
||||
if (resultMatrix.buffer == NULL) {
|
||||
return resultMatrix;
|
||||
}
|
||||
for (unsigned int i = 0; i < matrix2.rows*matrix2.cols; i++) {
|
||||
unsigned int rowIdx = i / matrix2.cols;
|
||||
resultMatrix.buffer[i] = matrix2.buffer[i] + matrix1.buffer[rowIdx];
|
||||
}
|
||||
}
|
||||
return resultMatrix;
|
||||
}
|
||||
return resultMatrix;
|
||||
|
||||
}
|
||||
else {
|
||||
Matrix result;
|
||||
|
||||
@@ -99,7 +112,7 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
result.buffer = NULL;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user