diff --git a/src/mnist/mnist.c b/src/mnist/mnist.c index 992a0e3..be8b00a 100644 --- a/src/mnist/mnist.c +++ b/src/mnist/mnist.c @@ -90,7 +90,7 @@ int*** read_mnist_images(char* filename) { fread(&width, sizeof(unsigned int), 1, ptr); width = swap_endian(width); - int*** tab = (int***)malloc(sizeof(int**)*width*height); + int*** tab = (int***)malloc(sizeof(int**)*number_of_images); for (int i=0; i < number_of_images; i++) { tab[i] = read_image(width, height, ptr); diff --git a/test/mnist.c b/test/mnist.c new file mode 100644 index 0000000..cfe533b --- /dev/null +++ b/test/mnist.c @@ -0,0 +1,52 @@ +#include +#include +#include + +#include "../src/mnist/mnist.c" + + +void test_lecture(int nb_images, int width, int height, int*** images, unsigned int* labels) { + printf("\tLecture des labels\n"); + for (int i=0; i < nb_images; i++) { + (void)labels[i]; + } + printf("\tOK\n"); + printf("\tLecture des images\n"); + for (int i=0; i < nb_images; i++) { + for (int j=0; j < height; j++) { + for (int k=0; k < width; k++) { + (void)images[i][j][k]; + } + } + } + printf("\tOK\n"); +} + +int main() { + char* image_file = "data/t10k-images-idx3-ubyte"; + char* labels_file = "data/t10k-labels-idx1-ubyte"; + printf("Chargement des paramètres\n"); + + int* parameters = read_mnist_images_parameters(image_file); + int nb_images = parameters[0]; + int height = parameters[1]; + int width = parameters[2]; + + printf("OK\n"); + printf("Chargement des images\n"); + + int*** images = read_mnist_images(image_file); + + printf("OK\n"); + printf("Chargement des labels\n"); + + unsigned int* labels = read_mnist_labels(labels_file); + + printf("OK\n"); + printf("Vérification de l'accès en lecture\n"); + + test_lecture(nb_images, width, height, images, labels); + + printf("OK\n"); + return 1; +} \ No newline at end of file