generated from freudenreichan/info2Praktikum-NeuronalesNetz
addmatrix fertig Testdatei PASS
This commit is contained in:
parent
7513db75b9
commit
7f797957aa
45
matrix.c
45
matrix.c
@ -45,7 +45,50 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
return matrix1;
|
||||
int matrixResultCols;
|
||||
|
||||
if(matrix1.cols <= matrix2.cols){
|
||||
matrixResultCols = matrix2.cols;
|
||||
}
|
||||
else{
|
||||
matrixResultCols = matrix1.cols;
|
||||
}
|
||||
|
||||
Matrix result = createMatrix(matrix1.rows, matrixResultCols);
|
||||
|
||||
if(matrix1.rows != matrix2.rows){
|
||||
|
||||
result.buffer = NULL;
|
||||
result.rows = 0;
|
||||
result.cols = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
if(matrix1.cols == matrix2.cols){
|
||||
for(int i = 0; i < matrix1.rows; i++){
|
||||
for(int j = 0; j < matrix1.cols; j++){
|
||||
*(result.buffer + (matrix1.cols * i + j)) = *(matrix1.buffer + (matrix1.cols * i + j)) + *(matrix2.buffer + (matrix2.cols * i + j)) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((matrix1.cols ==1 && matrix2.cols != 1)){
|
||||
for(int i = 0; i < matrix2.rows; i++){
|
||||
for(int j = 0; j < matrix2.cols; j++){
|
||||
*(result.buffer + (result.cols * i + j)) = *(matrix2.buffer + (matrix2.cols * i + j)) + *(matrix1.buffer + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((matrix2.cols == 1 && matrix1.cols != 1)){
|
||||
for(int i = 0; i < matrix1.rows; i++){
|
||||
for(int j = 0; j < matrix1.cols; j++){
|
||||
*(result.buffer + (result.cols * i + j)) = *(matrix1.buffer + (matrix1.cols * i + j)) + *(matrix2.buffer + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user