jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 7b168b0f7f4853961d3b982cc43a396223b6f865
parent 9f72f0065cbedbbc4ecc7351b20bc2137cfeaf8a
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Sun, 11 Oct 2020 11:53:38 -0700

Tentatively declaring file reading bugs fixed

Diffstat:
Msrc/bpnn.cpp | 2++
Msrc/bpnn.hpp | 1+
Msrc/data.cpp | 17++++++++++++++---
3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/src/bpnn.cpp b/src/bpnn.cpp @@ -363,6 +363,7 @@ float Network::validate(char* path) val_acc = 1.0/(static_cast<float>(val_instances/batch_size)) * accsum; val_cost = 1.0/(static_cast<float>(val_instances/batch_size)) * costsum; val_data = open(VAL_BIN_PATH, O_RDONLY | O_NONBLOCK); + Ensures(lseek(val_data, 0, SEEK_CUR) == 0); return 0; } @@ -387,4 +388,5 @@ void Network::train() data = open(TRAIN_BIN_PATH, O_RDONLY | O_NONBLOCK); decay(); epochs++; + Ensures(lseek(data, 0, SEEK_CUR) == 0); } diff --git a/src/bpnn.hpp b/src/bpnn.hpp @@ -47,6 +47,7 @@ public: int val_data; int instances; std::byte buf[BUFFER_SIZE]; + std::byte* p; int val_instances; int test_instances; Eigen::MatrixXf numerical_grad(int i, float epsilon); diff --git a/src/data.cpp b/src/data.cpp @@ -42,10 +42,21 @@ int Network::next_batch(int fd) Expects(fd > 0); // File descriptor must be valid. uintmax_t lines = 0; while(size_t bytes_read = read(fd, buf, BUFFER_SIZE)) { - if (!bytes_read) { - break; + p = buf; + if (!bytes_read) break; + while(p < buf+BUFFER_SIZE) { + if (lines >= 10) return 0; + for (int i=0; i<layers[0].contents->cols(); ++i) {b + (*layers[0].contents)(lines,i) = *(reinterpret_cast<float*>(p)); + p += sizeof(float); + } + (*labels)(lines,0) = *(reinterpret_cast<float*>(p)); + p += sizeof(float); + ++lines; } - for(std::byte* p = buf; p < buf+BUFFER_SIZE;) { + } + if (p < buf+BUFFER_SIZE) { + while(p < buf+BUFFER_SIZE) { if (lines >= 10) return 0; for (int i=0; i<layers[0].contents->cols(); ++i) { (*layers[0].contents)(lines,i) = *(reinterpret_cast<float*>(p));