generated from freudenreichan/info2Praktikum-NeuronalesNetz
61 lines
1.3 KiB
C
61 lines
1.3 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "matrix.h"
|
|
|
|
// TODO Matrix-Funktionen implementieren
|
|
|
|
typedef struct Matrix {
|
|
unsigned int rows;
|
|
unsigned int cols;
|
|
MatrixType* buffer;
|
|
} 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)
|
|
{
|
|
|
|
}
|
|
|
|
Matrix add(const Matrix matrix1, const Matrix matrix2)
|
|
{
|
|
|
|
}
|
|
|
|
Matrix multiply(const Matrix matrix1, const Matrix matrix2)
|
|
{
|
|
if (matrix1.rows == matrix2.cols) {
|
|
Matrix result;
|
|
result.rows = matrix1.rows;
|
|
result.cols = matrix2.cols;
|
|
|
|
result.buffer = malloc(result.rows * result.cols * sizeof(MatrixType));
|
|
|
|
for(int i = 0; i < rows; i++) {
|
|
for(int j = 0; j < cols; j++) {
|
|
MatrixType value = 0;
|
|
for(int k = 0; k < matrix1.cols; k++) {
|
|
value += matrix1[i][k] * matrix2[k][j];
|
|
}
|
|
result.buffer[i][i] = value;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
printf("Die angegebenen Matrizen haben keine passenden Dimensionen für die Multiplikation");
|
|
return NULL;
|
|
} |