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

Ufunc where parameter causes array to be silently read out of bounds #9886

Closed
sergiocallegari opened this issue Oct 18, 2017 · 4 comments
Closed

Comments

@sergiocallegari
Copy link

When the where argument of a ufunc has a shape that exceeds that of the input argument of the ufunc, arrays are silently read out of bounds. For instance

np.log([10], where=[True, False])
Out[58]: array([  2.30258509,  31.5       ])

Is this the intended behavior?

@pv
Copy link
Member

pv commented Oct 18, 2017 via email

@eric-wieser
Copy link
Member

eric-wieser commented Oct 19, 2017

A pretty simple test is to reverse the where array:

>>> np.log([10], where=[False, True])
array([  5.03403489e+223,   2.30258509e+000])

An out of bounds error shouldn't mess up for entry 0, so this looks like it's the intended behaviour @pv describes.

@callegar
Copy link

OK, now I understand. Since the where is broadcast with the argument, the output get the length of the wider. The output array is allocated but not initialized. Because the function is not computed where "where" is false, some buckets in the output remain uninitialized.

Makes sense, sorry for the noise. Wonder if the documentation could be enriched a little.

@eric-wieser
Copy link
Member

eric-wieser commented Oct 19, 2017

Wonder if the documentation could be enriched a little.

You're right, the descriptions don't suggest that at all right now. The relevant docstrings are in numpy\core\code_generators\ufunc_docstrings.py and doc\source\reference\ufuncs.rst

What you're seeing is the interaction between out == None and where != True - the docs for where only describe the case when out != None.

Feel free to submit a patch with improved wording, or even just file an issue suggesting the new docstring.

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

No branches or pull requests

4 participants