Skip to content

[resubmitted] Fix poisson deviate for expected values ~> LONG_MAX #34

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

Closed
wants to merge 3 commits into from
Closed

[resubmitted] Fix poisson deviate for expected values ~> LONG_MAX #34

wants to merge 3 commits into from

Conversation

olsonse
Copy link

@olsonse olsonse commented Jan 10, 2011

This patch causes rk_poisson to simply return the mean value of the Poissonian when the distribution cannot be supported by the high-order bits of the long integer type. This patch simply checks whether the mean value is less than LONG_MAX - 10 * sqrt(LONG_MAX) before actually generating a random deviate. This ensures that at least 20*sigma (sigma=sqrt(mean value)) of width for the distribution--this should be plenty of width.

This patch also adds error checking for when the mean-value cannot be represented by a long integer. In this case, a ValueError is raised with the appropriate error message, similar to how ValueError is raised with the mean-value is specified less than zero.

Since we can't support a complete poissonian disribution for values on the order
and greater than LONG_MAX, we simply return the expected value for these very
large expected values.
@charris
Copy link
Member

charris commented Jan 22, 2011

I just can't shake the feeling that returning the mean isn't quite the right thing to do. Admittedly, the fractional error is small, but... perhaps we should simply raise an error for anything within 10 sigma of the maximum value.

I think you should raise this issue on the mailing list for discussion. If there is a particular reason this has been a problem for you, you should mention that.

For the implementation, I think you can import the max integer value from limits.h, something like

cdef extern from "limits.h":
    cdef int LONG_MAX

cdef long long_max = LONG_MAX

You could also compute the square root there.

@charris
Copy link
Member

charris commented Jan 23, 2011

I've put up a modified version that just checks for lam too big at charris@c231344.

Tests will also be needed.

@charris
Copy link
Member

charris commented Mar 10, 2011

I've gone ahead and merged a modified version. Thanks for noting this problem and coming up with a solution.

mattip referenced this pull request in mattip/numpy Mar 20, 2019
DOC: Update docs with Xoshiro additions
bashtage referenced this pull request in bashtage/numpy May 28, 2019
* PERF: Reorder header for philox

Reorder header so that support uint128 is always used if avilable, irrespective of platform
fangerer added a commit to hpyproject/numpy-hpy that referenced this pull request Jul 7, 2022
Merge in ~STEPAN.SINDELAR_ORACLE.COM/numpy-hpy from fa/fix_universal_crashes to labs-hpy-port

* commit '3e21b1a35e92fa196650a9a4cf6c438337b5342f':
  Migrate is_known_scalar_type_function
  Correctly convert to/from HPyArrayMethod_Context
luyahan pushed a commit to plctlab/numpy that referenced this pull request Apr 25, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants