From 3a096469efdf30d2d691d3ff1051d8bf46166913 Mon Sep 17 00:00:00 2001 From: Davis King Date: Thu, 28 Jul 2016 19:09:07 -0400 Subject: [PATCH] Changed code to avoid advancing iterator beyond end since some compilers complain about this (and it's technically not allowed in C++). --- dlib/dnn/core.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dlib/dnn/core.h b/dlib/dnn/core.h index dfb40c43f..cfd5803d1 100644 --- a/dlib/dnn/core.h +++ b/dlib/dnn/core.h @@ -2189,10 +2189,15 @@ namespace dlib { std::vector results(std::distance(data.begin(), data.end())); auto o = results.begin(); - for (auto i = data.begin(); i < data.end(); i+=batch_size, o+=batch_size) + auto i = data.begin(); + auto num_remaining = results.size(); + while(num_remaining != 0) { - auto end = std::min(i+batch_size, data.end()); - (*this)(i, end, o); + auto inc = std::min(batch_size, num_remaining); + (*this)(i, i+inc, o); + i += inc; + o += inc; + num_remaining -= inc; } return results; }