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

ENH: ufunc should warn when argument where is specified and out is default None. #23540

Open
Game4Move78 opened this issue Apr 6, 2023 · 2 comments

Comments

@Game4Move78
Copy link

Game4Move78 commented Apr 6, 2023

Proposed new feature or change:

My argument is that where makes sense unless out is default None, in which case it simply obscures the creation of a partially uninitialised array.

The casual numpy user accessing through the public API likely only wants garbage values if they have explicitly asked for them using empty_like. If they have decided not to provide out, it probably means they expect a partially transformed copy of the input array and have overlooked the note in the docstring.

Example:

User creates a function that takes log on values where log is defined .

def safe_log(val, out):
    return np.log(val, where=np.greater(val, 0), out=out)

User suddenly decides that they don't want to specify out every time, making safe_log unsafe.

def safe_log(val, out=None):
    return np.log(val, where=np.greater(val, 0), out=out)
@eric-wieser
Copy link
Member

The difficulty in using empty_like is that you now have to guess the right return type rather than letting np.log pick it for you.

@Game4Move78
Copy link
Author

@eric-wieser Thanks for your response. Is the difficulty with the return type of empty_like that it doesn't create scalars?

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

2 participants