This commit is contained in:
Max-R 2025-11-18 10:51:55 +01:00
commit 5fcc3cd042
6 changed files with 71 additions and 4 deletions

Binary file not shown.

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# Projekt 2 für Informatik 2 Praktikum

View File

@ -7,16 +7,23 @@
#define FILE_HEADER_STRING "__info2_image_file_format__"
// TODO Implementieren Sie geeignete Hilfsfunktionen für das Lesen der Bildserie aus einer Datei
GrayScaleImage readImage()
{
}
// TODO Vervollständigen Sie die Funktion readImages unter Benutzung Ihrer Hilfsfunktionen
GrayScaleImageSeries *readImages(const char *path)
{
GrayScaleImageSeries *series = NULL;
FILE *file = fopen("mnist_test.info2","rb");
char headOfFile;
series = malloc();
return series;
}
// TODO Vervollständigen Sie die Funktion clearSeries, welche eine Bildserie vollständig aus dem Speicher freigibt
void clearSeries(GrayScaleImageSeries *series)
{
}

View File

@ -6,12 +6,14 @@
typedef float MatrixType;
// TODO Matrixtyp definieren
typedef struct{
typedef struct
{
unsigned int rows;
unsigned int cols;
MatrixType *data; //Zeiger auf Speicher (Reihen*Spalten)
MatrixType *data;
} 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);

View File

@ -71,6 +71,32 @@ void test_addFailsOnDifferentInputDimensions(void)
TEST_ASSERT_EQUAL_UINT32(0, result.cols);
}
void test_addSupportsBroadcasting(void)
{
MatrixType buffer1[] = {1, 2, 3, 4, 5, 6};
MatrixType buffer2[] = {7, 8};
Matrix matrix1 = {.rows=2, .cols=3, .buffer=buffer1};
Matrix matrix2 = {.rows=2, .cols=1, .buffer=buffer2};
Matrix result1 = add(matrix1, matrix2);
Matrix result2 = add(matrix2, matrix1);
float expectedResults[] = {8, 9, 10, 12, 13, 14};
TEST_ASSERT_EQUAL_UINT32(matrix1.rows, result1.rows);
TEST_ASSERT_EQUAL_UINT32(matrix1.cols, result1.cols);
TEST_ASSERT_EQUAL_UINT32(matrix1.rows, result2.rows);
TEST_ASSERT_EQUAL_UINT32(matrix1.cols, result2.cols);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults)/sizeof(expectedResults[0]), result1.rows * result1.cols);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, result1.buffer, result1.cols * result1.rows);
TEST_ASSERT_EQUAL_INT(sizeof(expectedResults)/sizeof(expectedResults[0]), result2.rows * result2.cols);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, result2.buffer, result2.cols * result2.rows);
free(result1.buffer);
free(result2.buffer);
}
void test_multiplyReturnsCorrectResults(void)
{
MatrixType buffer1[] = {1, 2, 3, 4, 5, 6};
@ -138,7 +164,7 @@ void test_setMatrixAtFailsOnIndicesOutOfRange(void)
Matrix matrixToTest = {.rows=2, .cols=3, .buffer=buffer};
setMatrixAt(-1, matrixToTest, 2, 3);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, matrixToTest.buffer, matrixToTest.cols * matrixToTest.rows);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedResults, matrixToTest.buffer, sizeof(buffer)/sizeof(MatrixType));
}
void setUp(void) {
@ -159,6 +185,7 @@ int main()
RUN_TEST(test_clearMatrixSetsMembersToNull);
RUN_TEST(test_addReturnsCorrectResult);
RUN_TEST(test_addFailsOnDifferentInputDimensions);
RUN_TEST(test_addSupportsBroadcasting);
RUN_TEST(test_multiplyReturnsCorrectResults);
RUN_TEST(test_multiplyFailsOnWrongInputDimensions);
RUN_TEST(test_getMatrixAtReturnsCorrectResult);

29
neuralN_readFiles Normal file
View File

@ -0,0 +1,29 @@
Inhalte: Dynamische Speicherverwaltung, Strukturen, Dateien lesen.
Ziel: Die Bilder aus mnist_test.info 2 auslesen
Struktur für einlesen des Strings am Anfang der Datei:
int AnzahlBilder
int breiteBilder
int LaengeBilder
Struktur für Bilder:
unsinged int array Breite * Höhe
unsigned int Klasse (Label 0 - 9)
Speicher für Bilder dynamisch allokieren
GrayScaleImageSeries:
datei einlesen
header String aus der Datei lesen
mit header String den benötigten Speicher freigeben
in den Speicher die Datei einschreiben (mit Hilfsfunktion)
Hilfsfunktion (saveFile)
gehe zum Anfang des Strings
speicher alles der Reihe nach ein
clearSeries:
pointer der be malloc kommt nehemen
free()