-
-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cauchy distribution: optimise sampling #486
Conversation
I think you are right that |
I realised that might be possible, but frankly I don't think it would have much effect on the distribution (it's valid to sample from any π-length interval excluding the singularities). Probably though it would round towards zero anyway. |
75% plus of the time is spend in |
I agree, it would just wrap around, which is not a problem because it is a random number anyway.
More concretely, it cannot optimize |
@dhardy Since you are using Over the weekend I read some papers and I have implemented a stunningly fast numerical approximation method for generating Cauchy numbers. |
You're right; turns out removing the loop makes most of the difference. Moving everything inside the loop also performs well on my CPU, but I think we can just drop the loop since tan(π/2) rounds to a finite number anyway. |
Amended. @MaximoB that sounds worth looking into. I don't think this is the only distribution which could be sped up significantly using a different approach; see rust-random/rand_distr#9. If you're interested then please open a PR. |
This is unnecesary due to FP approximation resulting in rounding away from π/2, and significantly increases performance.
@MaximoB this presumably uses 1 bit less precision but is quite a bit faster
Optimisers are weird, but as I guessed, it seems we get a free subtraction operation when using
Open01
.I considered checking that the result is finite with a loop, but I'm fairly sure it must be anyway since π is irrational. Do you agree?