binomial distribution setter function

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

binomial distribution setter function

Boost - Dev mailing list
This is my first time posting in this mailing list. Not sure how to post to
the developer only mailing list after reading the document for mailing list
for a good half an hour.  If I posted in he wrong mailing please let me
know and kindly provide the developer mailing list.

I am looking at the binomial.hpp file.
I need to use the binomial object in a loop which requires to have high
performance.
I am thinking constructing the binomial object each time in the loop would
be less efficient than if I construct a single object, the each time reset
the p parameter and use the object.

I am not sure why the setter method was not provided.

296       RealType success_fraction() const
297       { // Probability.
298         return m_p;
299       }
300       void set_success_fraction(RealType p) {
301          m_p=p;
302       }
Line 296 is the getter method, I added the setter method at line 300.

--
Kemin Zhou
858 366 8260

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: binomial distribution setter function

Boost - Dev mailing list
Am 18.01.20 um 07:57 schrieb Kemin Zhou via Boost:

> I am looking at the binomial.hpp file.
> I need to use the binomial object in a loop which requires to have high
> performance.
> I am thinking constructing the binomial object each time in the loop would
> be less efficient than if I construct a single object, the each time reset
> the p parameter and use the object.
>
> I am not sure why the setter method was not provided.
>
> 296       RealType success_fraction() const
> 297       { // Probability.
> 298         return m_p;
> 299       }
> 300       void set_success_fraction(RealType p) {
> 301          m_p=p;
> 302       }
> Line 296 is the getter method, I added the setter method at line 300.
As usual: Did you measure before making assumptions about performance?
Next: Did you check what the ctor does? What is your reasoning for your
statement?

This is not meant to sound harsh but rather spark usual scientific work
practices.

You'll see that the constructor does nothing but check invariants. Your
setter does not do so and hence is wrong (for some definition of wrong
as usual)
So the only overhead can be due to check of valid parameters. Depending
on how you pass in the arguments this can even be removed, so try it
first and measure where your performance suffers or use e.g. godbolt to
check the assembly to verify assumptions.

Then the better solution would be to provide a ctor that does not do
verification, probably the policy system can be used if it isn't
already. Again it needs to be argued why this would be required and how
much benefit it brings.

Regards, Alex




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

smime.p7s (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: binomial distribution setter function

Boost - Dev mailing list


> -----Original Message-----
> From: Boost <[hidden email]> On Behalf Of Alexander Grund via
> Boost
> Sent: 20 January 2020 08:35
> To: [hidden email]
> Cc: Alexander Grund <[hidden email]>
> Subject: Re: [boost] binomial distribution setter function
>
> Am 18.01.20 um 07:57 schrieb Kemin Zhou via Boost:
> > I am looking at the binomial.hpp file.
> > I need to use the binomial object in a loop which requires to have
> > high performance.
> > I am thinking constructing the binomial object each time in the loop
> > would be less efficient than if I construct a single object, the each
> > time reset the p parameter and use the object.
> >
> > I am not sure why the setter method was not provided.
> >
> > 296       RealType success_fraction() const
> > 297       { // Probability.
> > 298         return m_p;
> > 299       }
> > 300       void set_success_fraction(RealType p) {
> > 301          m_p=p;
> > 302       }
> > Line 296 is the getter method, I added the setter method at line 300.
>
> As usual: Did you measure before making assumptions about performance?
> Next: Did you check what the ctor does? What is your reasoning for your
> statement?
>
> This is not meant to sound harsh but rather spark usual scientific work practices.
>
> You'll see that the constructor does nothing but check invariants. Your setter does
> not do so and hence is wrong (for some definition of wrong as usual) So the only
> overhead can be due to check of valid parameters. Depending on how you pass in
> the arguments this can even be removed, so try it first and measure where your
> performance suffers or use e.g. godbolt to check the assembly to verify
> assumptions.
>
> Then the better solution would be to provide a ctor that does not do verification,
> probably the policy system can be used if it isn't already. Again it needs to be
> argued why this would be required and how much benefit it brings.

I concur with this assessment.

I suspect that you presume that construction is expensive, when it is really very cheap, only carrying out some quick sanity checks, and a few assignments.

You need to be quite certain that these handful of instructions are on your critical path before doing something that will expose you to risks from passing a bad parameter.

Paul A. Bristow

PS Reminder, it you don't put your stuff inside try'n'catch blocks, you won't get any error messages helping you see what went wrong 😊

But of course that will slow things down a bit.  But useful to have the checks until you are certain that your code is correct?



_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost