lossless saving of floats

This commit is contained in:
Gustav Louw 2018-04-03 15:27:44 -07:00
parent a5913774b9
commit 6c115010e5

12
Tinn.c
View File

@ -154,18 +154,18 @@ Tinn xtbuild(const int nips, const int nhid, const int nops)
void xtsave(const Tinn t, const char* const path) void xtsave(const Tinn t, const char* const path)
{ {
FILE* const file = efopen(path, "wb"); FILE* const file = efopen(path, "w");
// Header. // Header.
fprintf(file, "%d %d %d\n", t.nips, t.nhid, t.nops); fprintf(file, "%d %d %d\n", t.nips, t.nhid, t.nops);
// Biases and weights. // Biases and weights.
for(int i = 0; i < t.nb; i++) fprintf(file, "%f\n", (double) t.b[i]); for(int i = 0; i < t.nb; i++) fprintf(file, "%a\n", (double) t.b[i]);
for(int i = 0; i < t.nw; i++) fprintf(file, "%f\n", (double) t.w[i]); for(int i = 0; i < t.nw; i++) fprintf(file, "%a\n", (double) t.w[i]);
fclose(file); fclose(file);
} }
Tinn xtload(const char* const path) Tinn xtload(const char* const path)
{ {
FILE* const file = efopen(path, "rb"); FILE* const file = efopen(path, "r");
int nips = 0; int nips = 0;
int nhid = 0; int nhid = 0;
int nops = 0; int nops = 0;
@ -174,8 +174,8 @@ Tinn xtload(const char* const path)
// A new tinn is returned. // A new tinn is returned.
const Tinn t = xtbuild(nips, nhid, nops); const Tinn t = xtbuild(nips, nhid, nops);
// Biases and weights. // Biases and weights.
for(int i = 0; i < t.nb; i++) fscanf(file, "%f\n", &t.b[i]); for(int i = 0; i < t.nb; i++) fscanf(file, "%a\n", &t.b[i]);
for(int i = 0; i < t.nw; i++) fscanf(file, "%f\n", &t.w[i]); for(int i = 0; i < t.nw; i++) fscanf(file, "%a\n", &t.w[i]);
fclose(file); fclose(file);
return t; return t;
} }