Boost logo

Boost :

Subject: Re: [boost] [math distributions] where to check for validity of distribution variables?
From: John Maddock (john_at_[hidden])
Date: 2008-11-27 05:19:16


Thijs van den Berg wrote:
>> Hahaha the compiler pointed that out! The non-member function get a
>> "const distribution" passed so it needs to const indeed!
>> I think a good place for a validation caching mechanism could be in
>> the constructor. The constructor can then set a private bool, and
>> that can
>> be accessed ala "RealType is_valid() const {..};"
>>
>> This would imply a small change of error reporting.
>> E.g. pdf(dist, x) will have two checks
>> 1) is dist valid?
>> 2) is x valid?
>>
>> The first check can throw a domain_error telling that the
>> distribution
>> has (some combination) of invalid parameters. The throwing can be
>> done
>> in the pdf function or in the is_valid() member function.. If we put
>> it
>> in the is_valid() member function, then it should maybe be called
>> check_validity(), to make it clearer that it's doing some action.
>> That's probably the best interface. check_validity() can either do a
>> check on
>> all parameters,or lookup a the cached checking result that was stored
>> during the initial checking done in the constructor.

Don't forget that the policy may be for domain errors to return a custom
error value - or take some other action - so you would have to store the
RealType result of the error checks on the parameters as well as the
true/false result.

>> John, I need to validate the code before you can waste your time on
>> it.
>> I'm currently collecting benchmark values & writing a test file. That
>> should get rid of all the bugs. Paul gave me some good help with
>> going
>> that way (with the test)

Nod.

John.


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