# binomial distribution setter function

5 messages
Open this post in threaded view
|

## binomial distribution setter function

 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
Open this post in threaded view
|

## Re: 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. Regards, Alex _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost smime.p7s (6K) Download Attachment
Open this post in threaded view
|