boostorg / histogram

Fast multi-dimensional generalized histogram with convenient interface for C++14
Boost Software License 1.0
313 stars 74 forks source link

Add collector accumulator #349

Open HDembinski opened 2 years ago

HDembinski commented 2 years ago

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

wiso commented 8 months ago

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.