| 6 | namespace bh = boost::histogram; |
| 7 | |
| 8 | int main() { |
| 9 | // make two histograms |
| 10 | auto h1 = bh::make_static_histogram(bh::axis::regular<>(2, -1, 1)); |
| 11 | auto h2 = bh::make_static_histogram(bh::axis::regular<>(2, -1, 1)); |
| 12 | |
| 13 | h1(-0.5); // counts are: 1 0 |
| 14 | h2(0.5); // counts are: 0 1 |
| 15 | |
| 16 | // add them |
| 17 | auto h3 = h1; |
| 18 | h3 += h2; // counts are: 1 1 |
| 19 | |
| 20 | // adding multiple histograms at once is efficient and does not create |
| 21 | // superfluous temporaries since operator+ functions are overloaded to |
| 22 | // accept and return rvalue references where possible |
| 23 | auto h4 = h1 + h2 + h3; // counts are: 2 2 |
| 24 | |
| 25 | std::cout << h4.at(0).value() << " " << h4.at(1).value() << std::endl; |
| 26 | // prints: 2 2 |
| 27 | |
| 28 | // multiply by number |
| 29 | h4 *= 2; // counts are: 4 4 |
| 30 | |
| 31 | // divide by number |
| 32 | auto h5 = h4 / 4; // counts are: 1 1 |
| 33 | |
| 34 | std::cout << h5.at(0).value() << " " << h5.at(1).value() << std::endl; |
| 35 | // prints: 1 1 |
| 36 | |
| 37 | // compare histograms |
| 38 | std::cout << (h4 == 4 * h5) << " " << (h4 != h5) << std::endl; |
| 39 | // prints: 1 1 |
| 40 | |
| 41 | // note: special effect of multiplication on counter variance |
| 42 | auto h = bh::make_static_histogram(bh::axis::regular<>(2, -1, 1)); |
| 43 | h(-0.5); // counts are: 1 0 |
| 44 | std::cout << "value " << (2 * h).at(0).value() << " " |
| 45 | << (h + h).at(0).value() << "\n" |
| 46 | << "variance " << (2 * h).at(0).variance() << " " |
| 47 | << (h + h).at(0).variance() << std::endl; |
| 48 | // equality operator also checks variances, so the statement is false |
| 49 | std::cout << (h + h == 2 * h) << std::endl; |
| 50 | /* prints: |
| 51 | value 2 2 |
| 52 | variance 4 2 |
| 53 | 0 |
| 54 | */ |
| 55 | } |
| 56 | |
| 57 | //] |
nothing calls this directly
no test coverage detected