Subject: Re: [boost] Suggestions for TMP/function introspection problem?
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2018-11-08 18:03:53
On 11/08/2018 10:27 AM, Hans Dembinski wrote:
>> On 7. Nov 2018, at 21:38, Steven Watanabe via Boost <boost_at_[hidden]> wrote:
>> On 11/07/2018 01:18 PM, Hans Dembinski via Boost wrote:
>>> I am trying to figure out how to solve an introspection problem since a few
>>> days, and I am not making progress. I could use some help, it is for
>>> boost.histogram. Maybe what I want is not possible...
>> I don't know what you need this for, but
>> I would recommend reconsidering why you
>> need this in the first place.
> It is for generic support of arbitrary accumulators per bin. Normally, a histogram gets some values equal to the number of axes, finds a corresponding bin and increments a counter for that bin. More generally, one can replace the counter by an accumulator that can accept an arbitrary number of values (the standard histogram is then the special case where the accumulator accepts zero arguments). Extra arguments passed to the histogram are forwarded to the accumulator. For example, an accumulator could compute a mean for values which end up in the same bin. This is what people in high energy physics call a "profile".
> // bin in 'x', compute a mean of 'y' for each bin in 'x'
> auto h = make_histogram_with(std::vector<mean_accumulator>(), axis::regular<>(10, 0, 1));
> // first argument is used to find the bin, second argument is passed to the mean_accumulator instance of that bin
> h(1, 2);
> The operator() of the accumulator could accept more than one value. Maybe you want to bin in 'x' and compute means for 'y' and 'z' at the same time. This should work and then you would pass three values to the histogram in total. I want to use the introspection for the accumulator to detect the number of arguments.
Okay. So the problem is that you're essentially
packing two variadic argument lists together and
you need to untangle them. I don't think that's
a good idea in the first place, as it makes the
meaning of user code unclear. I think it would
be better to distinguish them at the call-site
> I don't always know at compile-time how many arguments should be passed to the histogram axes (because one may use a dynamic histogram where the number of axis is only known at runtime), so I cannot just subtract the arguments that go to the axes and push the rest to the accumulator. But I could do it the other way round, subtract the arguments that need to go to the accumulator and pass the rest to the histogram axes.
In a dynamic histogram, why can't the accumulator
also be dynamic?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk