histogram icon indicating copy to clipboard operation
histogram copied to clipboard

Add collector accumulator

Open HDembinski opened this issue 3 years ago • 1 comments

A simple accumulator that just fills a std::vector with the samples passed to it. The user can then run any kind of statistical estimation on the sample. It is a very inefficient accumulator, but sometimes that's acceptable and the flexibility it offers is more important than the performance.

Pseudo-code

// C++17
namespace bh = boost::histogram;
auto h = bh::make_histogram(bh::axis::integer(0, 2),
              bh::dense_storage<bh::accumulators::Collector<>>());

// fill
h(0, 1);
h(0, 2);
h(0, 3);
h(1, 4);
h(1, 5);

for (auto x: h.at(0))
   std::cout << x << std::endl;

Prints: 1 2 3

HDembinski avatar Jan 19 '22 17:01 HDembinski

I think this would be a very nice feature since this is basically a groupby. I have submitted a simple PR. I am using collector instead of Collector for consistency with the other accumulators.

wiso avatar Nov 06 '23 11:11 wiso