From 986707af2b173c8c4b25f789f808392294bd5014 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Sat, 21 May 2022 15:11:36 +0200 Subject: [PATCH] Update neuron_io --- src/mnist/include/neuron_io.h | 9 ++++++++- src/mnist/neuron_io.c | 10 ++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mnist/include/neuron_io.h b/src/mnist/include/neuron_io.h index ced0ba5..aded44b 100644 --- a/src/mnist/include/neuron_io.h +++ b/src/mnist/include/neuron_io.h @@ -11,8 +11,15 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr); Neuron** read_neurons(uint32_t nb_neurons, uint32_t nb_weights, FILE *ptr); Network* read_network(char* filename); -void ecrire_neuron(Neuron* neuron, int weights, FILE *ptr); + +void write_neuron(Neuron* neuron, int weights, FILE *ptr); void write_network(char* filename, Network* network); + +Neuron* read_delta_neuron(uint32_t nb_weights, FILE *ptr); +Neuron** read_delta_neurons(uint32_t nb_neurons, uint32_t nb_weights, FILE *ptr); +Network* read_delta_network(char* filename); + +void write_delta_neuron(Neuron* neuron, int weights, FILE *ptr); void write_delta_network(char* filename, Network* network); #endif diff --git a/src/mnist/neuron_io.c b/src/mnist/neuron_io.c index 851fda4..bce26a2 100644 --- a/src/mnist/neuron_io.c +++ b/src/mnist/neuron_io.c @@ -27,11 +27,9 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) { neuron->last_back_bias = 0.0; neuron->back_bias = 0.0; - float* weights = (float*)malloc(sizeof(float)*nb_weights); - neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_weights); neuron->back_weights = (float*)malloc(sizeof(float)*nb_weights); - neuron->weights = weights; + neuron->weights = (float*)malloc(sizeof(float)*nb_weights); for (int i=0; i < (int)nb_weights; i++) { fread(&tmp, sizeof(float), 1, ptr); @@ -40,7 +38,6 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) { neuron->last_back_weights[i] = 0.0; } - free(weights); return neuron; } @@ -160,11 +157,9 @@ Neuron* read_delta_neuron(uint32_t nb_weights, FILE *ptr) { neuron->last_back_bias = 0.0; neuron->back_bias = back_bias; - float* back_weights = (float*)malloc(sizeof(float)*nb_weights); - neuron->last_back_weights = (float*)malloc(sizeof(float)*nb_weights); neuron->back_weights = (float*)malloc(sizeof(float)*nb_weights); - neuron->weights = back_weights; + neuron->weights = (float*)malloc(sizeof(float)*nb_weights); for (int i=0; i < (int)nb_weights; i++) { fread(&tmp, sizeof(float), 1, ptr); @@ -172,7 +167,6 @@ Neuron* read_delta_neuron(uint32_t nb_weights, FILE *ptr) { neuron->back_weights[i] = tmp; neuron->last_back_weights[i] = 0.0; } - free(back_weights); return neuron; }