8000 ENH: Improve error message in multinomial by bashtage · Pull Request #18482 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

ENH: Improve error message in multinomial #18482

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

Merged
merged 4 commits into from
Feb 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address comments
  • Loading branch information
Kevin Sheppard committed Feb 26, 2021
commit e900be2bf367d2a90af922e56c27aadcd0581bdf
18 changes: 9 additions & 9 deletions numpy/random/_generator.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3758,15 +3758,15 @@ cdef class Generator:
if kahan_sum(pix, d-1) > (1.0 + 1e-12):
# When floating, but not float dtype, and close, improve the error
# 1.0001 works for float16 and float32
if (isinstance(pvals, np.ndarray) and
pvals.dtype != float and
np.issubdtype(pvals.dtype, np.floating) and
pvals.sum() < 1.0001):
msg = ("sum(pvals[:-1].astype(np.float64)) > 1.0. pvals are "
"cast to 64-bit floating point values prior to "
"checking the constraint. Changes in precision when "
"casting may produce violations even if "
"pvals[:-1].sum() <= 1.")
if (isinstance(pvals, np.ndarray)
and np.issubdtype(pvals.dtype, np.floating)
and pvals.dtype != float
and pvals.sum() < 1.0001):
msg = ("sum(pvals[:-1].astype(np.float64)) > 1.0. The pvals "
"array is cast to 64-bit floating point prior to "
"checking the sum. Precision changes when casting may "
"cause problems even if the sum of the original pvals "
"is valid.")
else:
msg = "sum(pvals[:-1]) > 1.0"
raise ValueError(msg)
Expand Down
0