39 const_iterator
end()
const {
48 template <
typename T_Other>
50 return m_size == other_range.m_size;
94 template <
typename T_Other>
96 return m_rows == other_range.m_size;
102 template <
class T_Stream,
typename T_Counter>
106 const std::string &label_prefix,
108 const std::size_t min_label_width,
109 const bool dump_footer,
110 const bool separate_last_row,
111 const unsigned int precision) {
113 std::size_t max_size =min_label_width;
117 const std::size_t total_size =max_size+3+2*2+
column_width;
118 std::string
line(total_size,
'-');
119 std::array<std::size_t,3> vertical_line_pos{0
u, max_size+3,
line.size()-1};
120 for (std::size_t
pos : vertical_line_pos) {
126 auto default_precision =
out.precision();
127 for (
const T_Counter &
a :
counter) {
128 if (separate_last_row &&
idx+1 ==
label.size()) {
132 out <<
"| " << (label_prefix.empty() ? std::left : std::right)
133 << std::setw(label_prefix.size()) << (
idx==0 ? label_prefix :
empty)
134 << std::setw(max_size-label_prefix.size()) <<
label[
idx] << std::right
136 <<
" | " << std::setw(
column_width) <<
a <<
" |" << std::endl;
139 out << std::setprecision(default_precision);
150 template <
class T_Stream,
typename T_Counter>
155 const std::string &top_left_label,
156 const std::string &label_prefix,
158 const std::size_t min_label_width,
159 const bool dump_header,
160 const bool dump_footer,
161 const bool separate_last_row,
162 const std::vector<unsigned int> &precision) {
163 if (
counter && row_label && column_label
164 &&
counter.equalSize(row_label)
166 std::size_t max_size =
std::max(top_left_label.size(),
static_cast<std::size_t
>(min_label_width));
167 for (
const std::string &
name : row_label ) {
168 max_size =
std::max(max_size,
name.size() + label_prefix.size());
171 for (
const std::string &
name : column_label ) {
174 std::size_t total_size =max_size+2*2;
175 for (std::size_t column_i=0; column_i<column_label.size(); ++column_i) {
176 total_size += the_width + 3;
178 std::string
line(total_size,
'-');
182 for (std::size_t column_i=0; column_i<column_label.size(); ++column_i) {
184 pos += the_width + 3;
188 out <<
line << std::endl <<
"| " << std::setw(max_size) << top_left_label <<
" |" << std::left;
189 for (
const std::string &
header : column_label ) {
190 out <<
" " << std::setw(the_width) <<
header <<
" |";
192 out << std::right << std::endl;
197 auto default_precision =
out.precision();
199 if (separate_last_row &&
idx+1 == row_label.size()) {
202 assert(
idx < row_label.size());
203 out <<
"| " << (label_prefix.empty() ? std::left : std::right)
204 << std::setw(label_prefix.size()) << (
idx==0 ? label_prefix :
empty)
205 << std::setw(max_size-label_prefix.size()) << row_label[
idx] << std::right <<
" |";
206 unsigned int col_i=0;
207 for (
const T_Counter &
a : a_row) {
209 << std::setprecision( (col_i < precision.size()
213 << std::setw(the_width) <<
a <<
" |";
219 out << std::setprecision(default_precision);
228 template <
typename T>
249 template <
typename T>
272 template <
typename T_index,
class T_
string>
274 std::initializer_list<std::pair<T_index, T_string> > a_list)
276 std::vector<std::string>
labels;
277 labels.resize( n_entries );
278 if (a_list.size() != n_entries) {
279 throw std::logic_error(
"Expected number of entries and elements in the initializer lists do not match.");
281 for (
auto elm : a_list) {
282 labels.at(elm.first) = std::move(elm.second);
287 template<
class T_Collection>
289 std::size_t max_width=0
u;
290 for (
const auto &elm :
col ) {
291 max_width =
std::max( max_width, elm.size());
298 [[maybe_unused]]
const std::size_t sub_categories,
299 [[maybe_unused]]
const std::size_t n_counter) {
303 [[maybe_unused]]
const std::size_t sub_categories,
304 [[maybe_unused]]
const std::size_t n_counter) {
308 [[maybe_unused]]
const std::size_t sub_categories,
309 [[maybe_unused]]
const std::size_t n_counter) {
319 template<
typename T_Output,
typename T_Input, const std::
size_t N>
321 const std::size_t sub_categories,
322 const std::vector< std::array<T_Input, N> > &input_counts) {
323 if (
categories*sub_categories!= input_counts.size()) {
324 std::stringstream
msg;
325 msg <<
"Category dimensions (" <<
categories <<
" * " << sub_categories <<
"="
326 << (
categories * sub_categories) <<
") and input counter container size "
327 << input_counts.size() <<
" do not match.";
328 throw std::logic_error(
msg.str());
330 std::vector<T_Output> output_counts;
331 output_counts.resize((
categories+1) * (sub_categories+1) *
N);
336 for (std::size_t sub_category_i=0;
337 sub_category_i < sub_categories;
339 for (std::size_t category_i=0; category_i<
categories; ++category_i) {
340 std::size_t src_idx = category_i * sub_categories + sub_category_i;
341 std::size_t dest_idx_base = sub_category_i * sub_category_stride + 0 * counter_stride;
342 std::size_t dest_idx_project_categories_base = dest_idx_base;
343 dest_idx_base += category_i * category_stride;
344 dest_idx_project_categories_base +=
categories * category_stride;
346 for (std::size_t counter_i=0; counter_i<
N; ++counter_i) {
347 std::size_t dest_idx=dest_idx_base + counter_i * counter_stride;
348 assert( src_idx < input_counts.size() && counter_i < input_counts[src_idx].size());
349 assert( dest_idx < output_counts.size());
350 output_counts[dest_idx] = input_counts[src_idx][counter_i];
351 assert( dest_idx_project_categories_base + counter_i * counter_stride < output_counts.size());
352 output_counts[dest_idx_project_categories_base + counter_i * counter_stride] += output_counts[dest_idx];
357 for (std::size_t category_i=0; category_i<=
categories; ++category_i) {
358 for (std::size_t counter_i=0; counter_i<
N; ++counter_i) {
359 std::size_t dest_idx_base = 0 * sub_category_stride + counter_i * counter_stride + category_i;
360 std::size_t dest_idx_project_sub_categories = sub_categories * sub_category_stride + dest_idx_base;
361 assert( dest_idx_project_sub_categories < output_counts.size() );
362 for (std::size_t sub_category_i=0;
363 sub_category_i<sub_categories;
365 std::size_t sub_category_idx = dest_idx_base + sub_category_i * sub_category_stride;
366 assert( sub_category_idx < output_counts.size() );
367 output_counts[dest_idx_project_sub_categories] += output_counts[sub_category_idx];
371 return output_counts;
376 std::vector< SummandDefinition > >;
380 template <
typename T>
383 return std::make_pair( std::vector< SummandDefinition > { std::make_pair(
static_cast<std::size_t
>(numerator),1)},
384 std::vector< SummandDefinition > { std::make_pair(
static_cast<std::size_t
>(
denominator),1)});
388 template <
typename T>
389 inline std::tuple< std::string, RatioDefinition >
399 template <
typename T>
401 return std::make_pair(
static_cast<std::size_t
>(counter_idx), multiplier) ;
406 std::size_t
computeSum(
const std::vector< SummandDefinition > &sum_def,
407 std::size_t eta_offset,
408 std::size_t row_stride,
410 const std::vector<std::size_t> &
stat);
413 return numerator!=0 ?
static_cast<float>(numerator/
static_cast<double>(
denominator)) : 0.f;
423 std::size_t eta_offset,
424 std::size_t row_stride,
426 const std::vector<std::size_t> &
stat) {
427 std::size_t numerator=
computeSum(ratio_def.first, eta_offset, row_stride, seed_i,
stat);
429 ?
computeSum(ratio_def.second, eta_offset, row_stride, seed_i,
stat)
437 std::vector< SummandDefinition >&&numerator,
439 return std::make_tuple(std::move(
name),
440 std::make_pair(std::move(numerator),
445 inline std::tuple<std::vector<std::string>, std::vector<RatioDefinition> >
448 std::tuple< std::vector<std::string>, std::vector<RatioDefinition> > splitted;
449 std::get<0>(splitted).reserve( a_ratio_list.size() );
450 for (
auto a_ratio : a_ratio_list) {
451 std::get<0>(splitted).emplace_back( std::move(std::get<0>(a_ratio)) );
453 std::get<1>(splitted).reserve( a_ratio_list.size() );
454 for (
auto a_ratio : a_ratio_list) {
455 std::get<1>(splitted).emplace_back( std::move(std::get<1>(a_ratio)) );
462 [[maybe_unused]]
const std::size_t sub_categories,
463 [[maybe_unused]]
const std::vector<RatioDefinition> &ratio_def) {
467 [[maybe_unused]]
const std::size_t sub_categories,
468 [[maybe_unused]]
const std::vector<RatioDefinition> &ratio_def) {
472 [[maybe_unused]]
const std::size_t sub_categories,
473 [[maybe_unused]]
const std::vector<RatioDefinition> &ratio_def) {
478 std::vector<float>
computeRatios(
const std::vector<RatioDefinition> &ratio_def,
480 const std::size_t sub_categories,
481 const std::vector< std::size_t> &
counter);
484 const std::vector<float> &
bins,
486 bool abs_value=
false,
488 std::stringstream range_label;
489 range_label << std::fixed << std::setprecision(precision);
490 if (bin_i==
bins.size()+1) {
491 range_label <<
" All " << variable_name;
495 std::stringstream value_str;
496 value_str << std::fixed << std::setprecision(precision) << 0.;
497 range_label << std::setw(4) << (abs_value ? value_str.str().c_str() :
"-inf") <<
"-";
500 range_label << std::setw(4) <<
bins.at(bin_i-1) <<
"-";
502 if (bin_i>=
bins.size()) {
503 range_label << std::setw(4) <<
"+inf";
506 range_label << std::setw(4) <<
bins.at(bin_i);
509 return range_label.str();
513 std::size_t eta_bin_i,
514 bool abs_eta=
false) {
520 template <
typename T, std::
size_t N>
522 const std::array<std::string, N> &
label) {
530 template <
typename T, std::
size_t Nrows, std::
size_t Ncolumns>
532 const std::array<std::string, Nrows> &row_label,
533 const std::array<std::string, Ncolumns> &column_label,
534 const std::string &top_left_label=
"") {
537 counter.size(), column_label.size(),
548 template <
typename T>
550 std::size_t start_idx,
551 std::size_t row_stride,
552 const std::vector<std::string> &row_label,
553 const std::vector<std::string> &column_label,
554 const std::string &top_left_label=
"") {
555 if (start_idx + (row_label.size()-1) * row_stride >=
counter.size() || row_stride < column_label.size()) {
556 std::stringstream
msg;
557 msg <<
"Counter dimension and label dimensions (" << row_label.size() <<
" * " << column_label.size()
558 <<
") do not match: [" << start_idx <<
", "
559 << start_idx <<
" + " << (row_label.size()-1) <<
" * " << row_stride <<
" = "
560 << (start_idx + (row_label.size()-1) * row_stride)
562 msg <<
" [row_labels:";
563 for (
const std::string &
label : row_label) {
566 msg <<
"; column_labels:";
567 for (
const std::string &
label : column_label) {
571 throw std::logic_error(
msg.str());
586 template <
typename T, std::
size_t N>
588 std::size_t start_row_idx,
589 std::size_t row_stride,
590 std::size_t start_column_idx,
591 std::size_t column_stride,
592 const std::vector<std::string> &row_label,
593 const std::vector<std::string> &column_label,
594 const std::string &top_left_label=
"") {
595 if (start_row_idx + (row_label.size()-1) * row_stride >=
counter.size()*
N
596 || start_column_idx + (column_label.size()-1) * column_stride >=
counter.size()*
N
597 || (row_stride*row_label.size()>column_stride && column_stride*column_label.size()>row_stride) ) {
598 std::stringstream
msg;
599 msg <<
"Counter dimension and label dimensions (" << row_label.size() <<
" * " << column_label.size()
600 <<
") do not match: [" << start_row_idx <<
", "
601 << start_row_idx <<
" + " << (row_label.size()-1) <<
" * " << row_stride <<
" = "
602 << (start_row_idx + (row_label.size()-1) * row_stride)
604 << start_column_idx <<
" + " << (column_label.size()-1) <<
" * " << column_stride <<
" = "
605 << (start_column_idx + (column_label.size()-1) * column_stride)
608 << (start_row_idx + (row_label.size()-1) * row_stride) <<
" >= " << (
counter.size()*
N)
609 <<
" || " << (start_column_idx + (column_label.size()-1) * column_stride) <<
" >= " << (
counter.size()*
N)
610 <<
" || ( " << (row_stride*row_label.size()) <<
" > " << column_stride <<
" && " << (column_stride*column_label.size()) <<
" > " << (row_stride)
612 msg <<
" [row_labels:";
613 for (
const std::string &
label : row_label) {
616 msg <<
"; column_labels:";
617 for (
const std::string &
label : column_label) {
621 throw std::logic_error(
msg.str());
637 template <
typename T>
639 const std::vector<std::string> &row_label,
640 const std::vector<std::string> &column_label,
641 const std::string &top_left_label=
"") {
642 return makeTable(
counter, 0
u, column_label.size(), row_label, column_label, top_left_label);
645 #ifdef GAUDIKERNEL_MSGSTREAM_H
649 template <
typename T>
658 stat.m_minLabelWidth,
660 stat.m_separateLastRow,
667 template <
typename T>
678 stat.m_minLabelWidth,
681 stat.m_separateLastRow,
688 template <
typename T>
697 stat.m_minLabelWidth,
699 stat.m_separateLastRow,
705 template <
typename T>
716 stat.m_minLabelWidth,
719 stat.m_separateLastRow,