commit 88d3ae9b6b2b0b7f670cc9e5fa0e2a9a8ba22881
parent 7ee161bd05d1cc64f2bc52d8e9e211f8800f1f64
Author: David Freifeld <freifeld.david@gmail.com>
Date: Sun, 27 Sep 2020 01:00:24 -0700
Banished C casts
Also skip validation if no validation data
Diffstat:
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/bpnn.cpp b/src/bpnn.cpp
@@ -69,6 +69,7 @@ void Layer::init_weights(Layer next)
(*v)(static_cast<int>(i / nodes), i%nodes) = 0;
(*m)(static_cast<int>(i / nodes), i%nodes) = 0;
}
+
}
Network::Network(char* path, int batch_sz, float learn_rate, float bias_rate, Regularization regularization, float l, float ratio, bool early_exit, float cutoff)
@@ -350,6 +351,7 @@ void Network::update_layer(float* vals, int datalen, int index)
float Network::validate(char* path)
{
+ if (val_instances == 0) return 0.0;
float costsum = 0;
float accsum = 0;
for (int i = 0; i <= val_instances-batch_size; i+=batch_size) {
diff --git a/src/data.cpp b/src/data.cpp
@@ -26,11 +26,11 @@ void prep(char* rname, char* wname)
}
if (!bytes_read) break;
for(char* p = buf;;) {
- char* bound = (char*)memchr(p, '\n', (buf + bytes_read) - p);
+ char* bound = static_cast<char*>(memchr(p, '\n', (buf + bytes_read) - p));
if (bound - p < 0) break; // Stop.
for (int i=0; i<5; ++i) {
tmp = scan(&p);
- fwrite((void*)&tmp, sizeof(float), 1, wptr);
+ fwrite(static_cast<void*>(&tmp), sizeof(float), 1, wptr);
}
p = bound + 1;
}
@@ -91,7 +91,7 @@ int prep_file(char* path, char* out_path)
int split_file(char* path, int lines, float ratio)
{
FILE* src = fopen(path, "r");
- if (!src) throw std::runtime_error{"split_file() could not open file for split."};
+ if (!src) throw std::runtime_error{"split_file() could not open file to split."};
FILE* test = fopen(VAL_PATH, "w");
FILE* train = fopen(TRAIN_PATH, "w");
int switch_line = round(ratio * lines);