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
17
matrix.c
17
matrix.c
@ -6,14 +6,12 @@
|
|||||||
|
|
||||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||||
{
|
{
|
||||||
Matrix m;
|
Matrix m = {0, 0, NULL};
|
||||||
|
|
||||||
m.buffer = NULL;
|
if (rows > 0 && cols > 0)
|
||||||
|
{
|
||||||
m.rows = rows;
|
m.rows = rows;
|
||||||
m.cols = cols;
|
m.cols = cols;
|
||||||
|
|
||||||
if (rows > 0 || cols > 0)
|
|
||||||
{
|
|
||||||
m.buffer = malloc(rows * cols * sizeof(int));
|
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;
|
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)
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||||
@ -85,7 +88,7 @@ Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|||||||
{
|
{
|
||||||
Matrix result = {0};
|
Matrix result = {0};
|
||||||
|
|
||||||
if (matrix1.cols != matrix2.rows)
|
if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
1
matrix.h
1
matrix.h
@ -11,7 +11,6 @@ typedef struct
|
|||||||
{
|
{
|
||||||
unsigned int rows; // Anzahl der Zeilen
|
unsigned int rows; // Anzahl der Zeilen
|
||||||
unsigned int cols; // Anzahl der Spalten
|
unsigned int cols; // Anzahl der Spalten
|
||||||
//void *buffer;
|
|
||||||
MatrixType *buffer; // Zeiger auf die Matrixdaten
|
MatrixType *buffer; // Zeiger auf die Matrixdaten
|
||||||
} Matrix;
|
} Matrix;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user