boostorg / histogram

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

Suggestion: expand reducer shortcut to ND #256

Closed henryiii closed 4 years ago

henryiii commented 4 years ago

Currently, there are two forms for each reducer, one that takes an axis number and works in ND histograms, and one that does not take an axis and only works in 1D. This could be generalized fairly naturally, I believe, to ND as well:

h.reduce(rebin(2), rebin(3))

would be supported in if h is a 2D histogram. If it was not a 2D, this would throw an exception, as it does now. Then h1.reduce(rebin(2)) is no longer a special case, but just the 1D form of the above rule.[^1]

This would add one of the benefits of the Python's UHI system (easy per-axis application) without adding new syntax, just generalizing a current one. This has a readability benefit, as you are guaranteed to see what happens on each axis.

Thoughts? Is this possible/reasonable/a good idea?


[^1]: Currently, for 1D histograms, listing multiple reducers without an axis is supported, and they all apply to axis 0. This could become a special case for 1D to preserve backward compatibility.

HDembinski commented 4 years ago

You are right, this should be added. Perhaps not too hard to implement on top of what we have...

HDembinski commented 4 years ago

These are good ideas, but I wouldn't take it as far as adding spacers. When you need a spacer, you might be better off just using the other type of interface. I like that the rule for 1D is no longer special, that's very nice thinking.

HDembinski commented 4 years ago

Closed in develop