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

fix safe_log on systems which use 32 bit floats #915

Merged
merged 2 commits into from
Jul 27, 2023
Merged

Conversation

HDembinski
Copy link
Member

Closes #913 see that issue for a detailed analysis by @stephanlachnit why the original naive code did not work everywhere.

Maybe this is related to #902, too.

@stephanlachnit Could you please check whether this fix indeed solves the issue? I cannot run tests on the affected systems.

@@ -116,7 +116,7 @@ class documentation for details.

def _safe_log(x):
# guard against x = 0
return np.log(x + 1e-323)
return np.log(np.maximum(np.finfo(x.dtype).smallest_normal, x))
Copy link
Contributor

Choose a reason for hiding this comment

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

It's probably faster if np.finfo(x.dtype).smallest_normal is placed in a separate variable so that it doesn't need to be evaluated every time. You can find my current patch here (includes a pytest adjustment).

Copy link
Member Author

Choose a reason for hiding this comment

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

In that case, we cannot select the subnormal that matches the dtype of x, but the current code does not work with numba anyway, so probably that's the solution to go for.

Copy link
Member Author

Choose a reason for hiding this comment

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

I went for your solution, could you check again? Now Numba works again.

@stephanlachnit
Copy link
Contributor

Could you please check whether this fix indeed solves the issue? I cannot run tests on the affected systems.

Unfortunately, it does not. You can find the logs for different architectures here.

I do have access to these architectures in theory. I can try to look into it again and maybe test it with some verbose output to see what's going on there.

@HDembinski
Copy link
Member Author

Really nice to see that Debian is distributing iminuit. When I was younger, I used Debian for many years.

@HDembinski
Copy link
Member Author

I am going to merge this, because it is definitely more safe as the old code, since it can handle negative x (which should never happen, but you never know).

If the issue persists, please reopen the issue.

@HDembinski HDembinski merged commit 813caaf into develop Jul 27, 2023
@HDembinski HDembinski deleted the fix_safe_log branch July 27, 2023 08:52
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.

_safe_log is not safe
2 participants