generated from freudenreichan/info2Praktikum-NeuronalesNetz
mutiplyMatrix implementierung
This commit is contained in:
1 parent
d31214f974
commit
e8eb227d44
2 files changed
+39
-7
No files matched your search
+37
-4
@@ -2,6 +2,8 @@
|
||||
#include <string.h>
|
||||
#include "matrix.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// TODO Matrix-Funktionen implementieren
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
@@ -38,8 +40,12 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
{
|
||||
MatrixType testHelp = 0;
|
||||
return testHelp;
|
||||
if(matrix.rows > rowIdx && matrix.cols > colIdx){
|
||||
return matrix.buffer[colIdx + rowIdx * matrix.cols];
|
||||
}else{
|
||||
return UNDEFINED_MATRIX_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
@@ -50,6 +56,33 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
Matrix testHelp = {NULL, 0,0};
|
||||
return testHelp;
|
||||
Matrix resultMatrix = createMatrix(matrix1.rows,matrix2.cols);
|
||||
|
||||
if(matrix1.cols == matrix2.rows){
|
||||
unsigned int commonDimension = matrix1.cols;
|
||||
|
||||
for(int i = 0; i < resultMatrix.rows; i++){
|
||||
|
||||
for(int j = 0; j < resultMatrix.cols; j++){
|
||||
MatrixType entry = 0;
|
||||
|
||||
for(int k = 0; k < commonDimension; k++){
|
||||
entry += (matrix1.buffer[k + i * matrix1.cols] * matrix2.buffer[j + k * matrix2.cols]);
|
||||
}
|
||||
|
||||
resultMatrix.buffer[j + i * resultMatrix.cols] = entry;
|
||||
}
|
||||
}
|
||||
|
||||
return resultMatrix;
|
||||
}else{
|
||||
resultMatrix.buffer = NULL;
|
||||
resultMatrix.rows = 0;
|
||||
resultMatrix.cols = 0;
|
||||
return resultMatrix;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user