Browse Source

Merge pull request #7 from amboar/misc-cleanups

Miscellaneous cleanups
pull/14/head
Lewis Van Winkle 3 years ago
committed by GitHub
parent
commit
4dd67e42bc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 19 deletions
  1. +6
    -13
      Makefile
  2. +4
    -1
      example4.c
  3. +20
    -5
      genann.c

+ 6
- 13
Makefile View File

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

+ 4
- 1
example4.c View File

@ -42,7 +42,10 @@ void load_data() {
double *c = class + i * 3;
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, ",");
for (j = 0; j < 4; ++j) {


+ 20
- 5
genann.c View File

@ -25,11 +25,12 @@
#include "genann.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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) {
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);
int 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;


Loading…
Cancel
Save