$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] [math][distributions] superfluous checking ofparameters?
From: Thijs (M.A.) van den Berg (thijs_at_[hidden])
Date: 2011-10-29 13:08:10
>>> 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.
>
> HTH, John.
Thanks John. Makes perfect sense.
It's not a performance issue for me, I was curious about the idea behind it, I didn't see that straight away.
Also, Paul mentioned that distribution parameters might get modified after construction (but thinking a bit more about it, -and looking at the code- I cant see how they can get modified).
Thanks both for explaining the motivation, it's clear to me now