Boost logo

Boost :

Subject: Re: [boost] [math][distributions] superfluous checking of parameters?
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2011-10-29 08:04:52


> -----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?

Paul

---
Paul A. Bristow,
Prizet Farmhouse, Kendal LA8 8AB  UK
+44 1539 561830  07714330204
pbristow_at_[hidden]

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