Boost logo

Boost :

Subject: Re: [boost] [math][distributions] superfluous checking of parameters?
From: Thijs (M.A.) van den Berg (thijs_at_[hidden])
Date: 2011-10-29 08:23:27

>> -----Original Message-----
>> From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]] On Behalf Of Thijs
> (M.A.)
>> van den Berg
>> Sent: Saturday, October 29, 2011 10:56 AM
>> To: boost_at_[hidden]
>> Subject: [boost] [math][distributions] superfluous checking of parameters?
>> The boost math distributions check validity of distribution the same parameters multiple times.
>> E.g. in normal.hpp, class normal_distribution, the constructor,
>> normal_distribution(RealType mean = 0, RealType sd = 1)
>> : m_mean(mean), m_sd(sd)
>> { // Default is a 'standard' normal distribution N01.
>> static const char* function = "boost::math::normal_distribution<%1%>::normal_distribution";
>> RealType result;
>> detail::check_scale(function, sd, &result, Policy());
>> detail::check_location(function, mean, &result, Policy());
>> }
>> however, those are *again* checked in e.g. the pdf() non member function
>> inline RealType pdf(const normal_distribution<RealType, Policy>& dist, const RealType& x) { ...
>> if(false == detail::check_scale(function, sd, &result, Policy()))
>> {
>> return result;
>> }
>> ...
>> }
>> 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.
> Is there any evidence that this is a problem?

I hadn't though about the changing parameter user case. That's valid.

I don't think it's a problem, I mainly want to learn the design rationale and see if I need to check things in a similar same way in another project I'm working on, which I want to align the design with math.distributions

The changing parameter case is a good explanation and something I need to covert too. Thanks.

Boost list run by bdawes at, gregod at, cpdaniel at, john at