Skip to content
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

BUG: Better check for invalid bounds in np.random.uniform. #8227

Merged
merged 1 commit into from
Nov 5, 2016

Conversation

alimuldal
Copy link
Contributor

@alimuldal alimuldal commented Oct 30, 2016

Closes #8226

@alimuldal alimuldal changed the title Fix for #8226 BUG: check for invalid bounds in np.random.uniform when low= and high= are arraylike rather than scalar. Oct 30, 2016
@charris
Copy link
Member

charris commented Oct 30, 2016

Could you fix up the commit message? All lines should be <=72 characters with hard breaks and a blank line after the summary line. Something like

BUG: Better check for invalid bounds in np.random.uniform.

extended, long winded explanation.

It would be extraordinary if the extended explanation were too detailed ;)

@charris charris changed the title BUG: check for invalid bounds in np.random.uniform when low= and high= are arraylike rather than scalar. BUG: Better check for invalid bounds in np.random.uniform. Oct 30, 2016
@alimuldal alimuldal force-pushed the uniform_inf_check branch 4 times, most recently from 139eb03 to 341ed78 Compare October 30, 2016 22:03
fscale = PyFloat_AsDouble(temp[i])
if not npy_isfinite(fscale):
raise OverflowError('Range exceeds valid bounds')

Py_INCREF(temp) # needed to get around Pyrex's automatic reference-counting
# rules because EnsureArray steals a reference
odiff = <ndarray>PyArray_EnsureArray(temp)
Copy link
Contributor

Choose a reason for hiding this comment

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

You could just use not np.any(np.isfinite(odiff)) here rather than manually looping. This is used multiple places, e.g.,

https://github.com/alimuldal/numpy/blob/341ed78f06e100c921de46b047fca8d7f77d5fca/numpy/random/mtrand/mtrand.pyx#L1642

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done.

Also check for invalid bounds when low= and high= are arraylike rather than scalar (closes numpy#8226)
@charris charris merged commit 8c49b92 into numpy:master Nov 5, 2016
@charris
Copy link
Member

charris commented Nov 5, 2016

Thanks @alimuldal .

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.

None yet

3 participants