From 6211c24a969735ecc9c83fceb59386c7d636253d Mon Sep 17 00:00:00 2001 From: Sascha Bischoff Date: Mon, 19 Aug 2013 03:52:29 -0400 Subject: [PATCH] stats: Fix issue when printing 2D vectors This patch addresses an issue with the text-based stats output which resulted in Vector2D stats being printed without subnames in the event that one of the dimensions was of length 1. This patch also fixes the total printing for the 2D vector. Previously totals were printed without explicitly stating that a total was being printed. This has been rectified in this patch. --- src/base/stats/text.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc index 3909c96ed..3b06dc121 100644 --- a/src/base/stats/text.cc +++ b/src/base/stats/text.cc @@ -249,6 +249,7 @@ struct VectorPrint int precision; VResult vec; Result total; + bool forceSubnames = false; void operator()(ostream &stream) const; }; @@ -279,6 +280,11 @@ VectorPrint::operator()(std::ostream &stream) const bool havesub = !subnames.empty(); if (_size == 1) { + // If forceSubnames is set, get the first subname (or index in + // the case where there are no subnames) and append it to the + // base name. + if (forceSubnames) + print.name = base + (havesub ? subnames[0] : to_string(0)); print.value = vec[0]; print(stream); return; @@ -550,6 +556,7 @@ Text::visit(const Vector2dInfo &info) print.separatorString = info.separatorString; print.descriptions = descriptions; print.precision = info.precision; + print.forceSubnames = true; if (!info.subnames.empty()) { for (off_type i = 0; i < info.x; ++i) @@ -558,7 +565,7 @@ Text::visit(const Vector2dInfo &info) } VResult tot_vec(info.y); - Result super_total = 0.0; + VResult super_total(1, 0.0); for (off_type i = 0; i < info.x; ++i) { if (havesub && (i >= info.subnames.size() || info.subnames[i].empty())) continue; @@ -571,7 +578,7 @@ Text::visit(const Vector2dInfo &info) yvec[j] = info.cvec[iy + j]; tot_vec[j] += yvec[j]; total += yvec[j]; - super_total += yvec[j]; + super_total[0] += yvec[j]; } print.name = info.name + "_" + @@ -582,11 +589,16 @@ Text::visit(const Vector2dInfo &info) print(*stream); } + // Create a subname for printing the total + vector total_subname; + total_subname.push_back("total"); + if (info.flags.isSet(::Stats::total) && (info.x > 1)) { print.name = info.name; + print.subnames = total_subname; print.desc = info.desc; - print.vec = tot_vec; - print.total = super_total; + print.vec = super_total; + print.flags = print.flags & ~total; print(*stream); } }