Skip to content

Commit

Permalink
fixed linux compile errors/warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
steffennissen committed Jan 22, 2012
1 parent 07d070c commit 65b7dde
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 24 deletions.
17 changes: 10 additions & 7 deletions src/fann.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "config.h"
#include "fann.h"

//#define FANN_NO_SEED
/* #define FANN_NO_SEED */

FANN_EXTERNAL struct fann *FANN_API fann_create_standard(unsigned int num_layers, ...)
{
Expand Down Expand Up @@ -106,7 +106,6 @@ FANN_EXTERNAL struct fann *FANN_API fann_create_sparse_array(float connection_ra
unsigned int random_number, found_connection, tmp_con;

#ifdef FIXEDFANN
unsigned int decimal_point;
unsigned int multiplier;
#endif
if(connection_rate > 1)
Expand All @@ -129,7 +128,6 @@ FANN_EXTERNAL struct fann *FANN_API fann_create_sparse_array(float connection_ra

ann->connection_rate = connection_rate;
#ifdef FIXEDFANN
decimal_point = ann->decimal_point;
multiplier = ann->multiplier;
fann_update_stepwise(ann);
#endif
Expand Down Expand Up @@ -403,7 +401,6 @@ FANN_EXTERNAL struct fann *FANN_API fann_create_shortcut_array(unsigned int num_
unsigned int num_neurons_in, num_neurons_out;

#ifdef FIXEDFANN
unsigned int decimal_point;
unsigned int multiplier;
#endif
/* seed random */
Expand All @@ -422,7 +419,6 @@ FANN_EXTERNAL struct fann *FANN_API fann_create_shortcut_array(unsigned int num_
ann->connection_rate = 1;
ann->network_type = FANN_NETTYPE_SHORTCUT;
#ifdef FIXEDFANN
decimal_point = ann->decimal_point;
multiplier = ann->multiplier;
fann_update_stepwise(ann);
#endif
Expand Down Expand Up @@ -834,7 +830,7 @@ FANN_EXTERNAL void FANN_API fann_randomize_weights(struct fann *ann, fann_type m
}

/* deep copy of the fann structure */
FANN_EXTERNAL struct fann* FANN_API fann_copy(const struct fann* orig)
FANN_EXTERNAL struct fann* FANN_API fann_copy(struct fann* orig)
{
struct fann* copy;
unsigned int num_layers = orig->last_layer - orig->first_layer;
Expand Down Expand Up @@ -1788,7 +1784,14 @@ void fann_seed_rand()
}
else
{
fread(&foo, sizeof(foo), 1, fp);
if(fread(&foo, sizeof(foo), 1, fp) != 1)
{
gettimeofday(&t, NULL);
foo = t.tv_usec;
#ifdef DEBUG
printf("unable to read from /dev/urandom\n");
#endif
}
fclose(fp);
}
srand(foo);
Expand Down
61 changes: 45 additions & 16 deletions src/fann_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,16 @@ struct fann *fann_create_from_fd_1_1(FILE * conf, const char *configuration_file
} \
}

#define fann_skip(name) \
{ \
if(fscanf(conf, name) != 0) \
{ \
fann_error(NULL, FANN_E_CANT_READ_CONFIG, name, configuration_file); \
fann_destroy(ann); \
return NULL; \
} \
}

/* INTERNAL FUNCTION
Create a network from a configuration file descriptor.
*/
Expand All @@ -377,7 +387,11 @@ struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file)
return NULL;
}

fread(read_version, 1, strlen(FANN_CONF_VERSION "\n"), conf); /* reads version */
if(fread(read_version, 1, strlen(FANN_CONF_VERSION "\n"), conf) != 1)
{
fann_error(NULL, FANN_E_CANT_READ_CONFIG, "FANN_VERSION", configuration_file);
return NULL;
}

/* compares the version information */
if(strncmp(read_version, FANN_CONF_VERSION "\n", strlen(FANN_CONF_VERSION "\n")) != 0)
Expand Down Expand Up @@ -412,22 +426,22 @@ struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file)
free(read_version);

#ifdef FIXEDFANN
fann_scanf("%u", "decimal_point", &decimal_point);
fann_scanf("%u", "decimal_point", &decimal_point);
multiplier = 1 << decimal_point;
#endif

fann_scanf("%u", "num_layers", &num_layers);
fann_scanf("%u", "num_layers", &num_layers);

ann = fann_allocate_structure(num_layers);
if(ann == NULL)
{
return NULL;
}

fann_scanf("%f", "learning_rate", &ann->learning_rate);
fann_scanf("%f", "connection_rate", &ann->connection_rate);
fann_scanf("%u", "network_type", &tmpVal);
ann->network_type = (enum fann_nettype_enum)tmpVal;
fann_scanf("%f", "learning_rate", &ann->learning_rate);
fann_scanf("%f", "connection_rate", &ann->connection_rate);
fann_scanf("%u", "network_type", &tmpVal);
ann->network_type = (enum fann_nettype_enum)tmpVal;
fann_scanf("%f", "learning_momentum", &ann->learning_momentum);
fann_scanf("%u", "training_algorithm", &tmpVal);
ann->training_algorithm = (enum fann_train_enum)tmpVal;
Expand Down Expand Up @@ -470,9 +484,17 @@ struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file)
return NULL;
}

fscanf(conf, "cascade_activation_functions=");

fann_skip("cascade_activation_functions=");
for(i = 0; i < ann->cascade_activation_functions_count; i++)
fscanf(conf, "%u ", (unsigned int *)&ann->cascade_activation_functions[i]);
{
if(fscanf(conf, "%u ", (unsigned int *)&ann->cascade_activation_functions[i]) != 1)
{
fann_error(NULL, FANN_E_CANT_READ_CONFIG, "cascade_activation_functions", configuration_file);
fann_destroy(ann);
return NULL;
}
}

fann_scanf("%u", "cascade_activation_steepnesses_count", &ann->cascade_activation_steepnesses_count);

Expand All @@ -487,9 +509,16 @@ struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file)
return NULL;
}

fscanf(conf, "cascade_activation_steepnesses=");
for(i = 0; i < ann->cascade_activation_steepnesses_count; i++)
fscanf(conf, FANNSCANF" ", &ann->cascade_activation_steepnesses[i]);
fann_skip("cascade_activation_steepnesses=");
for(i = 0; i < ann->cascade_activation_steepnesses_count; i++)
{
if(fscanf(conf, FANNSCANF" ", &ann->cascade_activation_steepnesses[i]) != 1)
{
fann_error(NULL, FANN_E_CANT_READ_CONFIG, "cascade_activation_steepnesses", configuration_file);
fann_destroy(ann);
return NULL;
}
}

#ifdef FIXEDFANN
ann->decimal_point = decimal_point;
Expand All @@ -505,7 +534,7 @@ struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file)
printf("input\n");
#endif

fscanf(conf, "layer_sizes=");
fann_skip("layer_sizes=");
/* determine how many neurons there should be in each layer */
for(layer_it = ann->first_layer; layer_it != ann->last_layer; layer_it++)
{
Expand Down Expand Up @@ -542,7 +571,7 @@ struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file)

#ifndef FIXEDFANN
#define SCALE_LOAD( what, where ) \
fscanf( conf, #what "_" #where "=" ); \
fann_skip( #what "_" #where "=" ); \
for(i = 0; i < ann->num_##where##put; i++) \
{ \
if(fscanf( conf, "%f ", (float *)&ann->what##_##where[ i ] ) != 1) \
Expand Down Expand Up @@ -578,7 +607,7 @@ struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file)
}

last_neuron = (ann->last_layer - 1)->last_neuron;
fscanf(conf, "neurons (num_inputs, activation_function, activation_steepness)=");
fann_skip("neurons (num_inputs, activation_function, activation_steepness)=");
for(neuron_it = ann->first_layer->first_neuron; neuron_it != last_neuron; neuron_it++)
{
if(fscanf
Expand Down Expand Up @@ -606,7 +635,7 @@ struct fann *fann_create_from_fd(FILE * conf, const char *configuration_file)
weights = ann->weights;
first_neuron = ann->first_layer->first_neuron;

fscanf(conf, "connections (connected_to_neuron, weight)=");
fann_skip("connections (connected_to_neuron, weight)=");
for(i = 0; i < ann->total_connections; i++)
{
if(fscanf(conf, "(%u, " FANNSCANF ") ", &input_neuron, &weights[i]) != 2)
Expand Down
2 changes: 1 addition & 1 deletion src/include/fann.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ FANN_EXTERNAL void FANN_API fann_destroy(struct fann *ann);
This function appears in FANN >= 2.2.0.
*/
FANN_EXTERNAL struct fann * FANN_API fann_copy(const struct fann *ann);
FANN_EXTERNAL struct fann * FANN_API fann_copy(struct fann *ann);


/* Function: fann_run
Expand Down

0 comments on commit 65b7dde

Please sign in to comment.