forked from freudenreichan/info2Praktikum-NeuronalesNetz
matrix.c und matrix.h, makefile für windows
This commit is contained in:
parent
28944bd871
commit
3c49920613
13
makefile
13
makefile
@ -57,10 +57,11 @@ imageInputTests: imageInput.o imageInputTests.c $(unityfolder)/unity.c
|
||||
# --------------------------
|
||||
# Clean
|
||||
# --------------------------
|
||||
#clean:
|
||||
#ifeq ($(OS),Windows_NT)
|
||||
# del /f *.o *.exe
|
||||
#else
|
||||
# rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests
|
||||
#endif
|
||||
clean:
|
||||
ifeq ($(OS),Windows_NT)
|
||||
del /f *.o *.exe
|
||||
else
|
||||
rm -f *.o mnist runMatrixTests runNeuralNetworkTests runImageInputTests
|
||||
endif
|
||||
|
||||
rm -f *.o *.exe
|
||||
56
matrix.c
56
matrix.c
@ -1,36 +1,38 @@
|
||||
#include "matrix.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "matrix.h"
|
||||
|
||||
// TODO Matrix-Funktionen implementieren
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
||||
{
|
||||
MatrixType* data = malloc(rows * cols * sizeof(MatrixType));
|
||||
Matrix newMatrix = {rows, cols, data};
|
||||
/*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)
|
||||
{
|
||||
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, unsigned int colIdx)
|
||||
{
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx,
|
||||
unsigned int colIdx) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
||||
{
|
||||
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2) {
|
||||
// broadcasting
|
||||
return matrix1;
|
||||
}
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2) { return matrix1; }
|
||||
|
||||
12
matrix.h
12
matrix.h
@ -6,20 +6,20 @@
|
||||
typedef float MatrixType;
|
||||
|
||||
// TODO Matrixtyp definieren
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
unsigned int rows;
|
||||
unsigned int cols;
|
||||
MatrixType *data;
|
||||
} Matrix;
|
||||
|
||||
} Matrix;
|
||||
|
||||
Matrix createMatrix(unsigned int rows, unsigned int cols);
|
||||
void clearMatrix(Matrix *matrix);
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx);
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx);
|
||||
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx,
|
||||
unsigned int colIdx);
|
||||
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx,
|
||||
unsigned int colIdx);
|
||||
Matrix add(const Matrix matrix1, const Matrix matrix2);
|
||||
Matrix multiply(const Matrix matrix1, const Matrix matrix2);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user