forked from freudenreichan/info2Praktikum-NeuronalesNetz
39 lines
1.4 KiB
C
39 lines
1.4 KiB
C
#include "matrix.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
// TODO Matrix-Funktionen implementieren
|
|
/*typedef struct {
|
|
unsigned int rows; //Zeilen
|
|
unsigned int cols; //Spalten
|
|
MatrixType *data; //Zeiger auf Speicherbereich Reihen*Spalten
|
|
} Matrix;*/
|
|
Matrix createMatrix(unsigned int rows, unsigned int cols) {
|
|
MatrixType *data =
|
|
malloc(rows * cols * sizeof(MatrixType)); // Speicher reservieren, malloc
|
|
// liefert Zeiger auf Speicher
|
|
Matrix newMatrix = {rows, cols, data}; // neue Matrix nach struct
|
|
return newMatrix;
|
|
}
|
|
void clearMatrix(Matrix *matrix) {
|
|
matrix->data = UNDEFINED_MATRIX_VALUE;
|
|
matrix->rows = UNDEFINED_MATRIX_VALUE;
|
|
matrix->cols = UNDEFINED_MATRIX_VALUE;
|
|
free((*matrix).data); // Speicher freigeben
|
|
}
|
|
void setMatrixAt(MatrixType value, Matrix matrix,
|
|
unsigned int rowIdx, // Kopie der Matrix wird übergeben
|
|
unsigned int colIdx) {
|
|
matrix.data[rowIdx * matrix.cols + colIdx] =
|
|
value; // rowIdx * matrix.cols -> Beginn der Zeile colIdx ->Spalte
|
|
// innerhalb der Zeile
|
|
}
|
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx,
|
|
unsigned int colIdx) {
|
|
return 0;
|
|
}
|
|
Matrix add(const Matrix matrix1, const Matrix matrix2) {
|
|
// broadcasting
|
|
return matrix1;
|
|
}
|
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; }
|