forked from freudenreichan/info2Praktikum-NeuronalesNetz
70 lines
1.6 KiB
C
70 lines
1.6 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "matrix.h"
|
|
|
|
// TODO Matrix-Funktionen implementieren
|
|
|
|
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)
|
|
{
|
|
// Überprüfen, ob die Matrizen gültig sind und ob ihre Dimensionen eine Multiplikation erlauben
|
|
if (matrix1.buffer == NULL || matrix2.buffer == NULL || matrix1.cols != matrix2.rows)
|
|
{
|
|
return (Matrix){0};
|
|
}
|
|
|
|
// Ergebnismatrix erstellen
|
|
Matrix result = createMatrix(matrix1.rows, matrix2.cols);
|
|
|
|
// Überprüfen, ob die Speicherreservierung erfolgreich war
|
|
if (result.buffer == NULL)
|
|
{
|
|
return (Matrix){0};
|
|
}
|
|
|
|
// Jede Zeile der ersten Matrix durchlaufen
|
|
for (unsigned int i = 0; i < matrix1.rows; i++)
|
|
{
|
|
// Jede Spalte der zweiten Matrix durchlaufen
|
|
for (unsigned int j = 0; j < matrix2.cols; j++)
|
|
{
|
|
MatrixType sum = 0;
|
|
|
|
// Summe der Produkte berechnen
|
|
for (unsigned int k = 0; k < matrix1.cols; k++)
|
|
{
|
|
sum += matrix1.buffer[i * matrix1.cols + k] *
|
|
matrix2.buffer[k * matrix2.cols + j];
|
|
}
|
|
|
|
// Berechneten Wert in der Ergebnismatrix speichern
|
|
result.buffer[i * result.cols + j] = sum;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
} |