Boost logo

Boost :

Subject: Re: [boost] [math][distributions] superfluous checking ofparameters?
From: Thijs (M.A.) van den Berg (thijs_at_[hidden])
Date: 2011-10-31 07:41:08


>>> Why is that? It's done in a consistent way across all distributions. Can we remove the check
>> inside the non
>>> member functions that are already checked in the constructor?
>>
>> As I recollect, I think we thought there were circumstances when this check wasn't redundant (but I
>> can't remember the exact case. Users changes the distribution parameters?).
>>
>> And because it was believed better to be safe than sorry, and the check was very cheap (at runtime),
>> we kept it that way.
>
> The issue is like this:
>
> * If the current policy (a template param) is to throw on domain errors (the default), then the second check in the non-member functions is redundant as any errors will have triggered an exception in the distribution constructor. On the other hand:
> * If the current policy is to not throw (return NaN on domain errors), then the constructor checks are redundant and the non-member function checks are the required ones.
>
> If it really is a performance bottleneck, then we could add a check on the current exception policy so that those two mutually exclusive options get optimized at compile time.

From a performance point of view, suppose I wanted to have a Policy mechanism that allows me to eliminate *all* error checking machine instructions from a distribution constructor of distribution non member function.

Would it be possible to move the detail::check_scale(d) etc into the Policy class? That way I could provide a different policy that get's eliminated compile time via an implementation like
"inline policy::check_scale(d){return;}"


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk