-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-108322: Optimize statistics.NormalDist.samples() #108324
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
Conversation
It looks impressive. But I wonder why not use this implementation in |
Tangentially: This PR would've been improved by code review from an active core dev as it borders on feature territory. Unfortunately stevendaprano has not yet chosen to return and thus may not even have been able to see the request let alone offer visible feedback. |
I see one potential problem with it from an API behavior change point of view in that people do rely on consistent output over time from functions like this when they specify an explicit seed value. We should retain the older slower implementation by default when an explicit seed value is specified. We're free to use a new faster version that returns different results when no explicit seed is provided given the nature of the function being randomness based. I'll make a PR. |
…les()` python#108324 switched to a faster implementation, but a caveat is that it changes the specific outputs. This preserves backwards compatibility when the user has asked for specific outputs by supplying a seed value. With an option for them to ask for the new algorithm implementation if desired. When return random values anyway (no seed), the new faster algorithm is used by default.
Timings show a 3.8x speedup:
Besides being faster, the PR makes the statistics module more self contained and less vulnerable to concurrency issues (because
gauss()
is stateful between successive calls).@stevendaprano
If you have comments or suggestions, feel free to send them to me privately.
📚 Documentation preview 📚: https://cpython-previews--108324.org.readthedocs.build/