forked from freudenreichan/info2Praktikum-NeuronalesNetz
Merge branch 'main' of https://git.efi.th-nuernberg.de/gitea/hallerni98888/info2Praktikum-NeuronalesNetz
This commit is contained in:
commit
42e92f278f
19
matrix.c
19
matrix.c
@ -6,14 +6,12 @@
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
{
|
||||
Matrix m;
|
||||
Matrix m = {0, 0, NULL};
|
||||
|
||||
m.buffer = NULL;
|
||||
m.rows = rows;
|
||||
m.cols = cols;
|
||||
|
||||
if (rows > 0 || cols > 0)
|
||||
if (rows > 0 && cols > 0)
|
||||
{
|
||||
m.rows = rows;
|
||||
m.cols = cols;
|
||||
m.buffer = malloc(rows * cols * sizeof(int));
|
||||
}
|
||||
|
||||
@ -46,7 +44,12 @@ MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int co
|
||||
{
|
||||
MatrixType value = 0;
|
||||
|
||||
return value = matrix.buffer[rowIdx * matrix.cols + colIdx]; // hole Wert value am Punkt (row col)
|
||||
if (rowIdx < matrix.rows && colIdx < matrix.cols)
|
||||
{
|
||||
value = matrix.buffer[rowIdx * matrix.cols + colIdx]; // hole Wert value am Punkt (row col)
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
@ -85,7 +88,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
Matrix result = {0};
|
||||
|
||||
if (matrix1.cols != matrix2.rows)
|
||||
if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user