generated from freudenreichan/info2Praktikum-NeuronalesNetz
fixed matrix errors
This commit is contained in:
parent
3adc90e98c
commit
963eb3b3a4
17
matrix.c
17
matrix.c
@ -5,11 +5,11 @@
|
||||
|
||||
// TODO Matrix-Funktionen implementieren
|
||||
|
||||
typedef struct Matrix {
|
||||
typedef struct Matrix{
|
||||
unsigned int rows;
|
||||
unsigned int cols;
|
||||
MatrixType* buffer;
|
||||
} Matrix;
|
||||
}Matrix;
|
||||
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
@ -31,10 +31,10 @@ void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned
|
||||
{
|
||||
if (rowIdx >= matrix.rows || colIdx >= matrix.cols){
|
||||
printf("Index out of bounds\n"); //Error Message because Index Input exceeds Matrix
|
||||
}
|
||||
}
|
||||
else{
|
||||
matrix.buffer[rowIdx * matrix.cols + colIdx] = value; //Writes Value of value variable in the selected place in Matrix
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||
@ -47,8 +47,8 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
||||
|
||||
MatrixType value = matrix.buffer[rowIdx * matrix.cols + colIdx]; //Stores value of selected place of Matrix in value variable
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
@ -65,16 +65,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
//Adding Matrix Elements of same row and col index together and store in new Matrix
|
||||
MatrixErgebnis.buffer[i * matrix1.cols + j] = matrix1.buffer[i * matrix1.cols + j] + matrix2.buffer[i * matrix1.cols + j];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return MatrixErgebnis;
|
||||
}
|
||||
return MatrixErgebnis;
|
||||
}
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
Matrix result;
|
||||
result.rows = matrix1.rows;
|
||||
result.cols = matrix2.cols;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user