generated from freudenreichan/info2Praktikum-NeuronalesNetz
setMatrixAt implementiert und mit add angefangen
This commit is contained in:
1 parent
fe8088ec40
commit
d56dfd6622
1 file changed
+51
@@ -29,6 +29,7 @@ Matrix createMatrix(unsigned int rows, unsigned int cols){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void clearMatrix(Matrix *matrix){ //*matrix greift auf die einträge im Struct Matrix zu
|
void clearMatrix(Matrix *matrix){ //*matrix greift auf die einträge im Struct Matrix zu
|
||||||
|
|
||||||
if (matrix == NULL) { //Wenn Matrix schon leer ist, mach nichts
|
if (matrix == NULL) { //Wenn Matrix schon leer ist, mach nichts
|
||||||
@@ -43,10 +44,22 @@ void clearMatrix(Matrix *matrix){ //*matrix greift auf die einträge im St
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx){
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx){
|
||||||
|
|
||||||
|
if (rowIdx >= matrix.rows || colIdx >= matrix.cols) { //Gibt fehler bei falschen Idx werten aus / !Arraysyntax beachten, bei 5 rows ist im Array 0 bis 4 deviniert!
|
||||||
|
fprintf(stderr, "Error, the value could not be saved to the matrix...\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int memoryspace = 0;
|
||||||
|
unsigned int columnlength = matrix.cols;
|
||||||
|
|
||||||
|
memoryspace = (rowIdx * columnlength)+colIdx; //Erklärung in "getMatrixAt"
|
||||||
|
matrix.space[memoryspace] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx){
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx){
|
||||||
|
|
||||||
@@ -64,8 +77,46 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Matrix add(const Matrix matrix1, const Matrix matrix2){
|
Matrix add(const Matrix matrix1, const Matrix matrix2){
|
||||||
|
|
||||||
|
//Matrix erstellen, in der die additionsmatrix gespeichert wird
|
||||||
|
unsigned int maxrows = 0;
|
||||||
|
unsigned int maxcols = 0;
|
||||||
|
|
||||||
|
if(matrix1.rows >= matrix2.rows){maxrows = matrix1.rows;}
|
||||||
|
//Maximale Anzahlen der Reihen bestimmen
|
||||||
|
else {maxrows = matrix2.rows;}
|
||||||
|
|
||||||
|
if(matrix1.cols >= matrix2.cols){maxcols = matrix1.cols;}
|
||||||
|
//Maximale Anzahl der Zeilen bestimmen
|
||||||
|
else {maxcols = matrix2.cols;}
|
||||||
|
|
||||||
|
Matrix summatrix = createMatrix(maxrows, maxcols); //Neue Matrix erstellen
|
||||||
|
|
||||||
|
|
||||||
|
//Checken ob Matrizenen werte haben
|
||||||
|
if(matrix1.space == 0 || matrix2.space ==0){
|
||||||
|
fprintf(stderr, "Error, addition of matrices was not possible...\n");
|
||||||
|
summatrix.rows = 0;
|
||||||
|
summatrix.cols = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Prüfen welches Additionsverfahren genurtz werden soll
|
||||||
|
|
||||||
|
if((matrix1.cols == 1 || matrix2.cols == 1) && matrix1.cols == matrix2.cols){ //Erkennung ob eine der Matrizen ein Vektor ist -> Broadcasting addition
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
for(int i = 0; i > summatrix.rows; i++){
|
||||||
|
summatrix.space[i]=
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return summatrix;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user