Add casts

This commit is contained in:
augustin64 2022-05-14 10:34:26 +02:00
parent ce947fe91d
commit 13c59de4ec
3 changed files with 23 additions and 23 deletions

View File

@ -1,7 +1,7 @@
#ifndef DEF_NEURON_H
#define DEF_NEURON_H
typedef struct Neuron{
typedef struct Neuron {
float* weights; // Liste de tous les poids des arêtes sortants du neurone
float bias; // Caractérise le bias du neurone
float z; // Sauvegarde des calculs faits sur le neurone (programmation dynamique)
@ -13,12 +13,12 @@ typedef struct Neuron{
} Neuron;
typedef struct Layer{
typedef struct Layer {
int nb_neurons; // Nombre de neurones dans la couche (longueur du tableau ci-dessous)
Neuron** neurons; // Tableau des neurones dans la couche
} Layer;
typedef struct Network{
typedef struct Network {
int nb_layers; // Nombre de couches dans le réseau neuronal (longueur du tableau ci-dessous)
Layer** layers; // Tableau des couches dans le réseau neuronal
} Network;

View File

@ -19,9 +19,9 @@ int** read_image(unsigned int width, unsigned int height, FILE* ptr) {
fread(buffer, sizeof(buffer), 1, ptr);
for (int i=0; i<height; i++) {
for (int i=0; i < (int)height; i++) {
int* line = (int*)malloc(line_size);
for (int j=0; j<width; j++) {
for (int j=0; j < (int)width; j++) {
line[j] = (int)buffer[j+i*width];
}
image[i] = line;
@ -31,7 +31,7 @@ int** read_image(unsigned int width, unsigned int height, FILE* ptr) {
// renvoie [nb_elem, width, height]
int* read_mnist_images_parameters(char* filename) {
int* tab = malloc(sizeof(int)*3);
int* tab = (int*)malloc(sizeof(int)*3);
FILE *ptr;
ptr = fopen(filename, "rb");
@ -113,7 +113,7 @@ int*** read_mnist_images(char* filename) {
int*** tab = (int***)malloc(sizeof(int**)*number_of_images);
for (int i=0; i < number_of_images; i++) {
for (int i=0; i < (int)number_of_images; i++) {
tab[i] = read_image(width, height, ptr);
}
return tab;
@ -142,9 +142,9 @@ unsigned int* read_mnist_labels(char* filename) {
unsigned char buffer[number_of_items];
fread(buffer, sizeof(unsigned char), number_of_items, ptr);
unsigned int* labels = malloc(sizeof(unsigned int)*number_of_items);
unsigned int* labels = (unsigned int*)malloc(sizeof(unsigned int)*number_of_items);
for (int i=0; i< number_of_items; i++) {
for (int i=0; i < (int)number_of_items; i++) {
labels[i] = (unsigned int)buffer[i];
}
return labels;

View File

@ -9,7 +9,7 @@
Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
Neuron* neuron = malloc(sizeof(Neuron));
Neuron* neuron = (Neuron*)malloc(sizeof(Neuron));
float activation;
float bias;
float tmp;
@ -23,13 +23,13 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
neuron->last_back_bias = 0.0;
neuron->back_bias = 0.0;
float* weights = malloc(sizeof(float)*nb_weights);
float* weights = (float*)malloc(sizeof(float)*nb_weights);
neuron->last_back_weights = malloc(sizeof(float)*nb_weights);
neuron->back_weights = 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;
for (int i=0; i < nb_weights; i++) {
for (int i=0; i < (int)nb_weights; i++) {
fread(&tmp, sizeof(float), 1, ptr);
neuron->weights[i] = tmp;
neuron->back_weights[i] = 0.0;
@ -42,8 +42,8 @@ Neuron* read_neuron(uint32_t nb_weights, FILE *ptr) {
// Lit une couche de neurones
Neuron** read_neurons(uint32_t nb_neurons, uint32_t nb_weights, FILE *ptr) {
Neuron** neurons = malloc(sizeof(Neuron*)*nb_neurons);
for (int i=0; i < nb_neurons; i++) {
Neuron** neurons = (Neuron**)malloc(sizeof(Neuron*)*nb_neurons);
for (int i=0; i < (int)nb_neurons; i++) {
neurons[i] = read_neuron(nb_weights, ptr);
}
return neurons;
@ -53,7 +53,7 @@ Neuron** read_neurons(uint32_t nb_neurons, uint32_t nb_weights, FILE *ptr) {
// Charge l'entièreté du réseau neuronal depuis un fichier binaire
Network* read_network(char* filename) {
FILE *ptr;
Network* network = malloc(sizeof(Network));
Network* network = (Network*)malloc(sizeof(Network));
ptr = fopen(filename, "rb");
@ -71,20 +71,20 @@ Network* read_network(char* filename) {
network->nb_layers = nb_layers;
Layer** layers = malloc(sizeof(Layer*)*nb_layers);
Layer** layers = (Layer**)malloc(sizeof(Layer*)*nb_layers);
uint32_t nb_neurons_layer[nb_layers+1];
network->layers = layers;
network->layers = layers;
for (int i=0; i < nb_layers; i++) {
layers[i] = malloc(sizeof(Layer));
for (int i=0; i < (int)nb_layers; i++) {
layers[i] = (Layer*)malloc(sizeof(Layer));
fread(&tmp, sizeof(tmp), 1, ptr);
layers[i]->nb_neurons = tmp;
nb_neurons_layer[i] = tmp;
}
nb_neurons_layer[nb_layers] = 0;
for (int i=0; i < nb_layers; i++) {
for (int i=0; i < (int)nb_layers; i++) {
layers[i]->neurons = read_neurons(layers[i]->nb_neurons, nb_neurons_layer[i+1], ptr);
}
@ -136,4 +136,4 @@ int write_network(char* filename, Network* network) {
fclose(ptr);
return 1;
}
}