From: William Wang Date: Tue, 5 Jun 2012 05:23:11 +0000 (-0400) Subject: stats: when applying an operation to two vectors sum the components first. X-Git-Tag: stable_2012_06_28~19 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e5f0d6016ba768c06b36d8b3d54f3ea700a4aa58;p=gem5.git stats: when applying an operation to two vectors sum the components first. Previously writing X/Y in a formula would result in: x[0]/y[0] + x[1]/y[1] In reality you want: (x[0] +x[1])/(y[0] + y[1]) --- diff --git a/src/base/statistics.hh b/src/base/statistics.hh index c36f8f461..723c8bd9c 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -2289,9 +2289,31 @@ class BinaryNode : public Node total() const { const VResult &vec = this->result(); + const VResult &lvec = l->result(); + const VResult &rvec = r->result(); Result total = 0.0; - for (off_type i = 0; i < size(); i++) + Result lsum = 0.0; + Result rsum = 0.0; + Op op; + + assert(lvec.size() > 0 && rvec.size() > 0); + assert(lvec.size() == rvec.size() || + lvec.size() == 1 || rvec.size() == 1); + + /** If vectors are the same divide their sums (x0+x1)/(y0+y1) */ + if (lvec.size() == rvec.size() && lvec.size() > 1) { + for (off_type i = 0; i < size(); ++i) { + lsum += lvec[i]; + rsum += rvec[i]; + } + return op(lsum, rsum); + } + + /** Otherwise divide each item by the divisor */ + for (off_type i = 0; i < size(); ++i) { total += vec[i]; + } + return total; }