Merge pull request #7 from amboar/misc-cleanups

Miscellaneous cleanups
This commit is contained in:
Lewis Van Winkle 2017-11-28 11:43:09 -06:00 committed by GitHub
commit 4dd67e42bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 19 deletions

View File

@ -1,32 +1,25 @@
CCFLAGS = -Wall -Wshadow -O2 -g CCFLAGS = -Wall -Wshadow -O2 -g
LFLAGS = -lm LDLIBS = -lm
all: test example1 example2 example3 example4 all: test example1 example2 example3 example4
test: test.o genann.o test: test.o genann.o
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
./$@
check: test
./$^
example1: example1.o genann.o example1: example1.o genann.o
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
example2: example2.o genann.o example2: example2.o genann.o
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
example3: example3.o genann.o example3: example3.o genann.o
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
example4: example4.o genann.o example4: example4.o genann.o
$(CC) $(CCFLAGS) -o $@ $^ $(LFLAGS)
.c.o:
$(CC) -c $(CCFLAGS) $< -o $@
clean: clean:
rm *.o $(RM) *.o
rm *.exe $(RM) *.exe
rm persist.txt $(RM) persist.txt

View File

@ -42,7 +42,10 @@ void load_data() {
double *c = class + i * 3; double *c = class + i * 3;
c[0] = c[1] = c[2] = 0.0; c[0] = c[1] = c[2] = 0.0;
fgets(line, 1024, in); if (fgets(line, 1024, in) == NULL) {
perror("fgets");
exit(1);
}
char *split = strtok(line, ","); char *split = strtok(line, ",");
for (j = 0; j < 4; ++j) { for (j = 0; j < 4; ++j) {

View File

@ -25,11 +25,12 @@
#include "genann.h" #include "genann.h"
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <math.h>
#include <assert.h>
#include <stdio.h>
#define LOOKUP_SIZE 4096 #define LOOKUP_SIZE 4096
@ -122,13 +123,27 @@ genann *genann_init(int inputs, int hidden_layers, int hidden, int outputs) {
genann *genann_read(FILE *in) { genann *genann_read(FILE *in) {
int inputs, hidden_layers, hidden, outputs; int inputs, hidden_layers, hidden, outputs;
fscanf(in, "%d %d %d %d", &inputs, &hidden_layers, &hidden, &outputs); int rc;
errno = 0;
rc = fscanf(in, "%d %d %d %d", &inputs, &hidden_layers, &hidden, &outputs);
if (rc < 4 || errno != 0) {
perror("fscanf");
return NULL;
}
genann *ann = genann_init(inputs, hidden_layers, hidden, outputs); genann *ann = genann_init(inputs, hidden_layers, hidden, outputs);
int i; int i;
for (i = 0; i < ann->total_weights; ++i) { for (i = 0; i < ann->total_weights; ++i) {
fscanf(in, " %le", ann->weight + i); errno = 0;
rc = fscanf(in, " %le", ann->weight + i);
if (rc < 1 || errno != 0) {
perror("fscanf");
genann_free(ann);
return NULL;
}
} }
return ann; return ann;