generated from freudenreichan/info2Praktikum-NeuronalesNetz
Fixed editing of matrix values by defenition
This commit is contained in:
parent
04d9b35c36
commit
9bd18d3681
14
matrix.c
14
matrix.c
@ -75,7 +75,9 @@ void clearMatrix(Matrix *matrix)
|
|||||||
{
|
{
|
||||||
for (int i = 0; i < matrix->rows; i++) {
|
for (int i = 0; i < matrix->rows; i++) {
|
||||||
for (int j = 0; j < matrix->cols;j++) {
|
for (int j = 0; j < matrix->cols;j++) {
|
||||||
matrix->buffer[i + matrix->rows * j] = UNDEFINED_MATRIX_VALUE;
|
// Normally one would expect to work matrices like this, but it is supposed to be the other way around.
|
||||||
|
// matrix->buffer[i + matrix->rows * j] = UNDEFINED_MATRIX_VALUE;
|
||||||
|
matrix->buffer[j + matrix->cols * i] = UNDEFINED_MATRIX_VALUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(matrix->buffer);
|
free(matrix->buffer);
|
||||||
@ -87,7 +89,11 @@ void clearMatrix(Matrix *matrix)
|
|||||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
//checks, if the given incies are allowed
|
//checks, if the given incies are allowed
|
||||||
if((rowIdx) < matrix.rows && (colIdx) < matrix.cols) matrix.buffer[rowIdx + matrix.rows*(colIdx)] = value;
|
if((rowIdx) < matrix.rows && (colIdx) < matrix.cols) {
|
||||||
|
// Normally one would expect to work matrices like this, but it is supposed to be the other way around.
|
||||||
|
// matrix.buffer[rowIdx + matrix.rows*(colIdx)] = value;
|
||||||
|
matrix.buffer[colIdx + matrix.cols * rowIdx] = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
||||||
@ -95,7 +101,9 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
|||||||
//checks, if the given indices are allowed
|
//checks, if the given indices are allowed
|
||||||
if((rowIdx) < matrix.rows && (colIdx) < matrix.cols) {
|
if((rowIdx) < matrix.rows && (colIdx) < matrix.cols) {
|
||||||
MatrixType returnVal;
|
MatrixType returnVal;
|
||||||
returnVal = matrix.buffer[rowIdx + matrix.rows*(colIdx)];
|
// Normally one would expect to work matrices like this, but it is supposed to be the other way around.
|
||||||
|
// returnVal = matrix.buffer[rowIdx + matrix.rows*(colIdx)];
|
||||||
|
returnVal = matrix.buffer[colIdx + rowIdx * matrix.cols];
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
else return 0;
|
else return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user