forked from freudenreichan/info2Praktikum-NeuronalesNetz
55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "matrix.h"
|
|
|
|
// TODO Matrix-Funktionen implementieren
|
|
|
|
Matrix createMatrix(unsigned int rows, unsigned int cols)
|
|
{
|
|
MatrixType **storage = __builtin_malloc(rows * cols * sizeof(int));
|
|
const Matrix matrix = {.rows = rows, .cols = cols, .storage = storage};
|
|
|
|
return matrix;
|
|
}
|
|
|
|
void clearMatrix(Matrix *matrix)
|
|
{
|
|
matrix->rows = 0;
|
|
matrix->cols = 0;
|
|
__builtin_free(matrix->storage);
|
|
}
|
|
|
|
void setMatrixAt(MatrixType value, Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
|
{
|
|
matrix.storage[rowIdx][colIdx] = value;
|
|
}
|
|
|
|
MatrixType getMatrixAt(const Matrix matrix, unsigned int rowIdx, unsigned int colIdx)
|
|
{
|
|
return matrix.storage[rowIdx][colIdx];
|
|
}
|
|
|
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|
{
|
|
if (matrix1.rows != matrix2.rows || matrix1.cols != matrix2.cols)
|
|
{
|
|
return matrix1;
|
|
}
|
|
|
|
Matrix result = createMatrix(matrix1.rows, matrix1.cols);
|
|
|
|
for (unsigned int i = 0; i < matrix1.rows; i++)
|
|
{
|
|
for (unsigned int j = 0; j < matrix1.cols; j++)
|
|
{
|
|
result.storage[i][j] = matrix1.storage[i][j] + matrix2.storage[i][j];
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|
{
|
|
|
|
} |