Skip to content

ENH: Stabilize Poisson computation for large lambda - #32026

Open
adrian740 wants to merge 6 commits into
numpy:mainfrom
adrian740:fix/large-poisson-variance
Open

ENH: Stabilize Poisson computation for large lambda#32026
adrian740 wants to merge 6 commits into
numpy:mainfrom
adrian740:fix/large-poisson-variance

Conversation

@adrian740

Copy link
Copy Markdown

PR summary

This PR addresses #31986 by implementing a stable calculation of Poisson log-PMF, adapted from dbinom.c.

It is about approximately 10% faster on average (only tested on my system) and does not suffer from instabilities at larger $$\lambda$$, as seen by this plot created by benchmark_poisson_ptrs.py.

performanceplot

First time committer introduction

I’m interested in contributing to open-source software, and this is my first pull request to NumPy. I hope to continue contributing in the future. I’d be grateful for any feedback from the maintainers.

AI Disclosure

I used Codex Sol Light to check the port of the code discussed in the original issue, and to create the benchmarking script. The submitted C changes and regression test were prepared with this assistance and reviewed and tested by me.

@ngoldbaum ngoldbaum changed the title Stabilize Poisson computation for large lambda ENH: Stabilize Poisson computation for large lambda Jul 17, 2026
@ngoldbaum

Copy link
Copy Markdown
Member

Ping @rkern

@ngoldbaum

ngoldbaum commented Jul 17, 2026

Copy link
Copy Markdown
Member

This will need a release note to be mergeable. See doc/release/upcoming_changes/README.rst for instructions on how to do that. I'm calling this an enhancement rather than a bugfix since this is a pretty big code change and I'm not sure if it's too risky to backport. Let me know if you think this should be backported.

@ngoldbaum ngoldbaum added 01 - Enhancement 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes labels Jul 17, 2026
@ngoldbaum ngoldbaum removed the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label Jul 17, 2026
Comment thread doc/release/upcoming_changes/32026.improvement.rst Outdated
Comment thread numpy/random/tests/test_random.py
@adrian740

Copy link
Copy Markdown
Author

I’m not sure why the cp313-ios_arm64_iphonesimulator-accelerate check failed. The wheel builds successfully, but the test run then hits many unrelated longdouble conversion errors. Do you have any insight into what might be causing this or how to address it?

@rkern rkern added this to the 2.6.0 Release milestone Jul 23, 2026

@rkern rkern left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failures are indeed unrelated, and therefore, happily, someone else's problem!

The code LGTM, thank you! The performance improvement is a nice bonus; thank you for checking. I have a minor request in the release note to raise the salience of the stream-changing effect.

Per NEP 19, we treat these kinds of changes as features rather than bug fixes, so I've slated this for the 2.6.0 release.

Comment thread doc/release/upcoming_changes/32026.improvement.rst Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants