-VectorPrint::operator()(std::ostream &stream) const
-{
- int _size = vec.size();
- result_t _total = 0.0;
-
- if (flags & (pdf | cdf)) {
- for (int i = 0; i < _size; ++i) {
- _total += vec[i];
- }
- }
-
- string base = name + ((mode == mode_simplescalar) ? "_" : "::");
-
- ScalarPrint print;
- print.name = name;
- print.desc = desc;
- print.precision = precision;
- print.flags = flags;
-
- bool havesub = !subnames.empty();
-
- if (_size == 1) {
- print.value = vec[0];
- print(stream);
- } else if (mode == mode_m5) {
- for (int i = 0; i < _size; ++i) {
- if (havesub && (i >= subnames.size() || subnames[i].empty()))
- continue;
-
- print.name = base + (havesub ? subnames[i] : to_string(i));
- print.desc = subdescs.empty() ? desc : subdescs[i];
- print.value = vec[i];
-
- if (_total && (flags & pdf)) {
- print.pdf = vec[i] / _total;
- print.cdf += print.pdf;
- }
-
- print(stream);
- }
-
- if (flags & ::Statistics::total) {
- print.name = base + "total";
- print.desc = desc;
- print.value = total;
- print(stream);
- }
- } else {
- if (flags & ::Statistics::total) {
- print.value = total;
- print(stream);
- }
-
- result_t _pdf = 0.0;
- result_t _cdf = 0.0;
- if (flags & dist) {
- ccprintf(stream, "%s.start_dist\n", name);
- for (int i = 0; i < _size; ++i) {
- print.name = havesub ? subnames[i] : to_string(i);
- print.desc = subdescs.empty() ? desc : subdescs[i];
- print.flags |= __substat;
- print.value = vec[i];
-
- if (_total) {
- _pdf = vec[i] / _total;
- _cdf += _pdf;
- }
-
- if (flags & pdf)
- print.pdf = _pdf;
- if (flags & cdf)
- print.cdf = _cdf;
-
- print(stream);
- }
- ccprintf(stream, "%s.end_dist\n", name);
- } else {
- for (int i = 0; i < _size; ++i) {
- if (havesub && subnames[i].empty())
- continue;
-
- print.name = base;
- print.name += havesub ? subnames[i] : to_string(i);
- print.desc = subdescs.empty() ? desc : subdescs[i];
- print.value = vec[i];
-
- if (_total) {
- _pdf = vec[i] / _total;
- _cdf += _pdf;
- } else {
- _pdf = _cdf = NAN;
- }
-
- if (flags & pdf) {
- print.pdf = _pdf;
- print.cdf = _cdf;
- }
-
- print(stream);
- }
- }
- }
-}
-
-struct DistPrint
-{
- string name;
- string desc;
- StatFlags flags;
- DisplayMode mode;
- int precision;
-
- result_t min_val;
- result_t max_val;
- result_t underflow;
- result_t overflow;
- rvec_t vec;
- result_t sum;
- result_t squares;
- result_t samples;
-
- int min;
- int max;
- int bucket_size;
- int size;
- bool fancy;
-
- void operator()(ostream &stream) const;
-};
-
-void
-DistPrint::operator()(ostream &stream) const
-{
- if (fancy) {
- ScalarPrint print;
- string base = name + ((mode == mode_m5) ? "::" : "_");
-
- print.precision = precision;
- print.flags = flags;
- print.mode = mode;
- print.desc = desc;
-
- print.name = base + "mean";
- print.value = samples ? sum / samples : NAN;
- print(stream);
-
- print.name = base + "stdev";
- print.value = samples ? sqrt((samples * squares - sum * sum) /
- (samples * (samples - 1.0))) : NAN;
- print(stream);
-
- print.name = "**Ignore: " + base + "TOT";
- print.value = samples;
- print(stream);
- return;
- }
-
- assert(size == vec.size());
-
- result_t total = 0.0;
-
- total += underflow;
- for (int i = 0; i < size; ++i)
- total += vec[i];
- total += overflow;
-
- string base = name + (mode == mode_m5 ? "::" : ".");
-
- ScalarPrint print;
- print.desc = (mode == mode_m5) ? desc : "";
- print.flags = flags;
- print.mode = mode;
- print.precision = precision;
-
- if (mode == mode_simplescalar) {
- ccprintf(stream, "%-42s", base + "start_dist");
- if (PrintDescriptions && !desc.empty())
- ccprintf(stream, " # %s", desc);
- stream << endl;
- }
-
- print.name = base + "samples";
- print.value = samples;
- print(stream);
-
- print.name = base + "min_value";
- print.value = min_val;
- print(stream);
-
- if (mode == mode_m5 || underflow > 0.0) {
- print.name = base + "underflows";
- print.value = underflow;
- if (mode == mode_m5 && total) {
- print.pdf = underflow / total;
- print.cdf += print.pdf;
- }
- print(stream);
- }
-
-
- if (mode == mode_m5) {
- for (int i = 0; i < size; ++i) {
- stringstream namestr;
- namestr << name;
-
- int low = i * bucket_size + min;
- int high = ::min((i + 1) * bucket_size + min - 1, max);
- namestr << low;
- if (low < high)
- namestr << "-" << high;
-
- print.name = namestr.str();
- print.value = vec[i];
- if (total) {
- print.pdf = vec[i] / total;
- print.cdf += print.pdf;
- }
- print(stream);
- }
-
- } else {
- int _min;
- result_t _pdf;
- result_t _cdf = 0.0;
-
- print.flags = flags | __substat;
-
- for (int i = 0; i < size; ++i) {
- if (flags & nozero && vec[i] == 0.0 ||
- flags & nonan && isnan(vec[i]))
- continue;
-
- _min = i * bucket_size + min;
- _pdf = vec[i] / total * 100.0;
- _cdf += _pdf;
-
-
- print.name = ValueToString(_min, mode, 0);
- print.value = vec[i];
- print.pdf = (flags & pdf) ? _pdf : NAN;
- print.cdf = (flags & cdf) ? _cdf : NAN;
- print(stream);
- }
-
- print.flags = flags;
- }
-
- if (mode == mode_m5 || overflow > 0.0) {
- print.name = base + "overflows";
- print.value = overflow;
- if (mode == mode_m5 && total) {
- print.pdf = overflow / total;
- print.cdf += print.pdf;
- } else {
- print.pdf = NAN;
- print.cdf = NAN;
- }
- print(stream);
- }
-
- print.pdf = NAN;
- print.cdf = NAN;
-
- if (mode != mode_simplescalar) {
- print.name = base + "total";
- print.value = total;
- print(stream);
- }
-
- print.name = base + "max_value";
- print.value = max_val;
- print(stream);
-
- if (mode != mode_simplescalar && samples != 0) {
- print.name = base + "mean";
- print.value = sum / samples;
- print(stream);
-
- print.name = base + "stdev";
- print.value = sqrt((samples * squares - sum * sum) /
- (samples * (samples - 1.0)));
- print(stream);
- }
-
- if (mode == mode_simplescalar)
- ccprintf(stream, "%send_dist\n\n", base);
-}
-
-void
-ScalarDataBase::display(ostream &stream, DisplayMode mode) const
-{
- ScalarPrint print;
- print.value = val();
- print.name = name;
- print.desc = desc;
- print.flags = flags;
- print.mode = mode;
- print.precision = precision;
-
- print(stream);
-}
-
-void
-VectorDataBase::display(ostream &stream, DisplayMode mode) const
-{
- int size = this->size();
- const_cast<VectorDataBase *>(this)->update();
-
- VectorPrint print;
-
- print.name = name;
- print.desc = desc;
- print.flags = flags;
- print.mode = mode;
- print.precision = precision;
- print.vec = val();
- print.total = total();
-
- if (!subnames.empty()) {
- for (int i = 0; i < size; ++i) {
- if (!subnames[i].empty()) {
- print.subnames = subnames;
- print.subnames.resize(size);
- for (int i = 0; i < size; ++i) {
- if (!subnames[i].empty() && !subdescs[i].empty()) {
- print.subdescs = subdescs;
- print.subdescs.resize(size);
- break;
- }
- }
- break;
- }
- }
- }
-
- print(stream);
-}
-
-void
-Vector2dDataBase::display(ostream &stream, DisplayMode mode) const
-{
- const_cast<Vector2dDataBase *>(this)->update();
-
- bool havesub = false;
- VectorPrint print;
-
- print.subnames = y_subnames;
- print.flags = flags;
- print.mode = mode;
- print.precision = precision;
-
- if (!subnames.empty()) {
- for (int i = 0; i < x; ++i)
- if (!subnames[i].empty())
- havesub = true;
- }
-
- rvec_t tot_vec(y);
- result_t super_total = 0.0;
- for (int i = 0; i < x; ++i) {
- if (havesub && (i >= subnames.size() || subnames[i].empty()))
- continue;
-
- int iy = i * y;
- rvec_t yvec(y);
-
- result_t total = 0.0;
- for (int j = 0; j < y; ++j) {
- yvec[j] = vec[iy + j];
- tot_vec[j] += yvec[j];
- total += yvec[j];
- super_total += yvec[j];
- }
-
- print.name = name + "_" + (havesub ? subnames[i] : to_string(i));
- print.desc = desc;
- print.vec = yvec;
- print.total = total;
- print(stream);
- }
-
- if ((flags & ::Statistics::total) && (x > 1)) {
- print.name = name;
- print.desc = desc;
- print.vec = tot_vec;
- print.total = super_total;
- print(stream);
- }
-}
-
-void
-DistDataBase::display(ostream &stream, DisplayMode mode) const
-{
- const_cast<DistDataBase *>(this)->update();
-
- DistPrint print;
-
- print.name = name;
- print.desc = desc;
- print.flags = flags;
- print.mode = mode;
- print.precision = precision;
-
- print.min_val = data.min_val;
- print.max_val = data.max_val;
- print.underflow = data.underflow;
- print.overflow = data.overflow;
- print.vec = data.vec;
- print.sum = data.sum;
- print.squares = data.squares;
- print.samples = data.samples;
-
- print.min = data.min;
- print.max = data.max;
- print.bucket_size = data.bucket_size;
- print.size = data.size;
- print.fancy = data.fancy;
-
- print(stream);
-}
-
-void
-VectorDistDataBase::display(ostream &stream, DisplayMode mode) const
-{
- const_cast<VectorDistDataBase *>(this)->update();
-
- for (int i = 0; i < size(); ++i) {
- DistPrint print;
-
- print.name = name +
- (subnames[i].empty() ? ("_" + to_string(i)) : subnames[i]);
- print.desc = subdescs[i].empty() ? desc : subdescs[i];
- print.flags = flags;
- print.mode = mode;
- print.precision = precision;
-
- print.min_val = data[i].min_val;
- print.max_val = data[i].max_val;
- print.underflow = data[i].underflow;
- print.overflow = data[i].overflow;
- print.vec = data[i].vec;
- print.sum = data[i].sum;
- print.squares = data[i].squares;
- print.samples = data[i].samples;
-
- print.min = data[i].min;
- print.max = data[i].max;
- print.bucket_size = data[i].bucket_size;
- print.size = data[i].size;
- print.fancy = data[i].fancy;
-
- print(stream);
- }
-}
-
-void
-ScalarDataBase::python(Python &py) const
-{
- py.name("Scalar");
- py.qarg(name);
- py.qqqarg(desc);
- py.kwarg("binned", binned());
- py.kwarg("precision", precision);
- py.kwarg("flags", flags);
- if (prereq)
- py.qkwarg("prereq", prereq->name);
- py.kwarg("value", val());
- py.nameEnd();
-}
-
-void
-VectorDataBase::python(Python &py) const
-{
- const_cast<VectorDataBase *>(this)->update();
-
- py.name("Vector");
- py.qarg(name);
- py.qqqarg(desc);
- py.kwarg("binned", binned());
- py.kwarg("precision", precision);
- py.kwarg("flags", flags);
- if (prereq)
- py.qkwarg("prereq", prereq->name);
- py.kwarg("value", val());
- if (!subnames.empty())
- py.qkwarg("subnames", subnames);
- if (!subdescs.empty())
- py.qkwarg("subdescs", subdescs);
- py.nameEnd();
-}
-
-void
-DistDataData::python(Python &py, const string &name) const
-{
- string s = name.empty() ? "" : name + "=";
-
- if (samples == 0 || fancy)
- s += "SimpleDist";
- else
- s += "FullDist";
-
- py.name(s);
- py.arg(sum);
- py.arg(squares);
- py.arg(samples);
- if (samples && !fancy) {
- py.arg(min_val);
- py.arg(min_val);
- py.arg(underflow);
- py.arg(vec);
- py.arg(overflow);
- py.arg(min);
- py.arg(max);
- py.arg(bucket_size);
- py.arg(size);
- }
- py.nameEnd();
-}
-
-void
-FormulaDataBase::python(Python &py) const
-{
- const_cast<FormulaDataBase *>(this)->update();
-
- py.name("Formula");
- py.qarg(name);
- py.qqqarg(desc);
- py.kwarg("binned", binned());
- py.kwarg("precision", precision);
- py.kwarg("flags", flags);
- if (prereq)
- py.qkwarg("prereq", prereq->name);
- py.qkwarg("formula", str());
- if (!subnames.empty())
- py.qkwarg("subnames", subnames);
- if (!subdescs.empty())
- py.qkwarg("subdescs", subdescs);
- py.nameEnd();
-}
-
-void
-DistDataBase::python(Python &py) const
-{
- const_cast<DistDataBase *>(this)->update();
-
- py.name("Dist");
- py.qarg(name);
- py.qqqarg(desc);
- py.kwarg("binned", binned());
- py.kwarg("precision", precision);
- py.kwarg("flags", flags);
- if (prereq)
- py.qkwarg("prereq", prereq->name);
- data.python(py, "dist");
- py.nameEnd();
-}
-
-void
-VectorDistDataBase::python(Python &py) const
-{
- const_cast<VectorDistDataBase *>(this)->update();
-
- py.name("VectorDist");
- py.qarg(name);
- py.qqqarg(desc);
- py.kwarg("binned", binned());
- py.kwarg("precision", precision);
- py.kwarg("flags", flags);
- if (prereq)
- py.qkwarg("prereq", prereq->name);
- if (!subnames.empty())
- py.qkwarg("subnames", subnames);
- if (!subdescs.empty())
- py.qkwarg("subdescs", subdescs);
-
- py.tuple("dist");
- typedef std::vector<DistDataData>::const_iterator iter;
- iter i = data.begin();
- iter end = data.end();
- while (i != end) {
- i->python(py, "");
- ++i;
- }
- py.tupleEnd();
- py.nameEnd();
-}
-
-void
-Vector2dDataBase::python(Python &py) const
-{
- const_cast<Vector2dDataBase *>(this)->update();
-
- py.name("Vector2d");
- py.qarg(name);
- py.qqqarg(desc);
- py.kwarg("binned", binned());
- py.kwarg("precision", precision);
- py.kwarg("flags", flags);
- if (prereq)
- py.qkwarg("prereq", prereq->name);
-
- py.kwarg("value", vec);
- if (!subnames.empty())
- py.qkwarg("subnames", subnames);
- if (!subdescs.empty())
- py.qkwarg("subdescs", subdescs);
- if (!y_subnames.empty())
- py.qkwarg("ysubnames", y_subnames);
-
- py.kwarg("x", x);
- py.kwarg("y", y);
- py.nameEnd();
-}
-
-void
-FormulaBase::val(rvec_t &vec) const