forked from freudenreichan/info2Praktikum-NeuronalesNetz
Rename Matrix.data to Matrix.buffer
This commit is contained in:
2 files changed
+15
-15
No files matched your search
+14
-14
@@ -10,9 +10,9 @@ Matrix createMatrix(unsigned int rows, unsigned int cols)
|
|||||||
matrix.rows = rows;
|
matrix.rows = rows;
|
||||||
matrix.cols = cols;
|
matrix.cols = cols;
|
||||||
|
|
||||||
matrix.data = calloc(rows * cols, sizeof(MatrixType));
|
matrix.buffer = calloc(rows * cols, sizeof(MatrixType));
|
||||||
|
|
||||||
if (matrix.data == NULL)
|
if (matrix.buffer == NULL)
|
||||||
{
|
{
|
||||||
matrix.rows = 0;
|
matrix.rows = 0;
|
||||||
matrix.cols = 0;
|
matrix.cols = 0;
|
||||||
@@ -26,9 +26,9 @@ void clearMatrix(Matrix* matrix)
|
|||||||
{
|
{
|
||||||
if (matrix != NULL)
|
if (matrix != NULL)
|
||||||
{
|
{
|
||||||
free(matrix->data);
|
free(matrix->buffer);
|
||||||
|
|
||||||
matrix->data = NULL;
|
matrix->buffer = NULL;
|
||||||
matrix->rows = 0;
|
matrix->rows = 0;
|
||||||
matrix->cols = 0;
|
matrix->cols = 0;
|
||||||
}
|
}
|
||||||
@@ -38,11 +38,11 @@ void clearMatrix(Matrix* matrix)
|
|||||||
void setMatrixAt(MatrixType value, Matrix matrix,
|
void setMatrixAt(MatrixType value, Matrix matrix,
|
||||||
unsigned int rowIdx, unsigned int colIdx)
|
unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
if (matrix.data != NULL &&
|
if (matrix.buffer != NULL &&
|
||||||
rowIdx < matrix.rows &&
|
rowIdx < matrix.rows &&
|
||||||
colIdx < matrix.cols)
|
colIdx < matrix.cols)
|
||||||
{
|
{
|
||||||
matrix.data[rowIdx * matrix.cols + colIdx] = value;
|
matrix.buffer[rowIdx * matrix.cols + colIdx] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,11 +50,11 @@ void setMatrixAt(MatrixType value, Matrix matrix,
|
|||||||
MatrixType getMatrixAt(const Matrix matrix,
|
MatrixType getMatrixAt(const Matrix matrix,
|
||||||
unsigned int rowIdx, unsigned int colIdx)
|
unsigned int rowIdx, unsigned int colIdx)
|
||||||
{
|
{
|
||||||
if (matrix.data != NULL &&
|
if (matrix.buffer != NULL &&
|
||||||
rowIdx < matrix.rows &&
|
rowIdx < matrix.rows &&
|
||||||
colIdx < matrix.cols)
|
colIdx < matrix.cols)
|
||||||
{
|
{
|
||||||
return matrix.data[rowIdx * matrix.cols + colIdx];
|
return matrix.buffer[rowIdx * matrix.cols + colIdx];
|
||||||
}
|
}
|
||||||
|
|
||||||
return UNDEFINED_MATRIX_VALUE;
|
return UNDEFINED_MATRIX_VALUE;
|
||||||
@@ -65,15 +65,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
{
|
{
|
||||||
if (matrix1.rows != matrix2.rows ||
|
if (matrix1.rows != matrix2.rows ||
|
||||||
matrix1.cols != matrix2.cols ||
|
matrix1.cols != matrix2.cols ||
|
||||||
matrix1.data == NULL ||
|
matrix1.buffer == NULL ||
|
||||||
matrix2.data == NULL)
|
matrix2.buffer == NULL)
|
||||||
{
|
{
|
||||||
return createMatrix(0, 0);
|
return createMatrix(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
|
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
|
||||||
|
|
||||||
if (result.data == NULL)
|
if (result.buffer == NULL)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -97,15 +97,15 @@ Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|||||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||||
{
|
{
|
||||||
if (matrix1.cols != matrix2.rows ||
|
if (matrix1.cols != matrix2.rows ||
|
||||||
matrix1.data == NULL ||
|
matrix1.buffer == NULL ||
|
||||||
matrix2.data == NULL)
|
matrix2.buffer == NULL)
|
||||||
{
|
{
|
||||||
return createMatrix(0, 0);
|
return createMatrix(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix result = createMatrix(matrix1.rows, matrix2.cols);
|
Matrix result = createMatrix(matrix1.rows, matrix2.cols);
|
||||||
|
|
||||||
if (result.data == NULL)
|
if (result.buffer == NULL)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
typedef float MatrixType;
|
typedef float MatrixType;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
MatrixType *data;
|
MatrixType *buffer;
|
||||||
unsigned int rows;
|
unsigned int rows;
|
||||||
unsigned int cols;
|
unsigned int cols;
|
||||||
} Matrix;
|
} Matrix;
|
||||||
|
|||||||
Reference in new issue
Block a user