From ea130335dabe2e21bb835aa12813c8fe870565f2 Mon Sep 17 00:00:00 2001 From: Gustav Louw Date: Sun, 1 Apr 2018 17:01:42 -0700 Subject: [PATCH] const correctness --- Tinn.c | 10 +++++----- Tinn.h | 7 ++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/Tinn.c b/Tinn.c index 412980b..af83896 100644 --- a/Tinn.c +++ b/Tinn.c @@ -52,8 +52,8 @@ static void backwards(const Tinn t, const float* in, const float* tg, float rate // Calculate total error change with respect to output. for(int j = 0; j < t.nops; j++) { - float a = pderr(t.o[j], tg[j]); - float b = pdact(t.o[j]); + const float a = pderr(t.o[j], tg[j]); + const float b = pdact(t.o[j]); sum += a * b * t.x[j * t.nhid + i]; // Correct weights in hidden to output layer. t.x[j * t.nhid + i] -= rate * a * b * t.h[i]; @@ -125,7 +125,7 @@ Tinn xtbuild(int nips, int nhid, int nops) void xtsave(const Tinn t, const char* path) { - FILE* file = fopen(path, "w"); + FILE* const file = fopen(path, "w"); // Header. fprintf(file, "%d %d %d\n", t.nips, t.nhid, t.nops); // Biases and weights. @@ -136,14 +136,14 @@ void xtsave(const Tinn t, const char* path) Tinn xtload(const char* path) { - FILE* file = fopen(path, "r"); + FILE* const file = fopen(path, "r"); int nips = 0; int nhid = 0; int nops = 0; // Header. fscanf(file, "%d %d %d\n", &nips, &nhid, &nops); // A new tinn is returned. - Tinn t = xtbuild(nips, nhid, nips); + const Tinn t = xtbuild(nips, nhid, nips); // Biases and weights. for(int i = 0; i < t.nb; i++) fscanf(file, "%f\n", &t.b[i]); for(int i = 0; i < t.nw; i++) fscanf(file, "%f\n", &t.w[i]); diff --git a/Tinn.h b/Tinn.h index 250edc5..610fac1 100644 --- a/Tinn.h +++ b/Tinn.h @@ -8,11 +8,8 @@ typedef struct float* h; // Hidden layer. float* o; // Output layer. - // Number of biases - always two - Tinn only supports a single hidden layer. - int nb; - - // Number of weights. - int nw; + int nb; // Number of biases - always two - Tinn only supports a single hidden layer. + int nw; // Number of weights. int nips; // Number of inputs. int nhid; // Number of hidden neurons.