Closed ipcamit closed 2 years ago
Yeah, this has been fixed in the latest release v0.3.3.
The problem in the previous version is that std::numeric_limits<double>::epsilon()
is used as eps
to be added to max
. Then when we do (max+eps) - min
, it got evaluated to 0
, instead of std::numeric_limits<double>::epsilon()
due to numerical error.
We fix it is by using a larger eps (1e-10 now). But I think something like index[0] = static_cast<int>(((x[0] - min[0]) / std::max(std::numeric_limits<double>::epsilon(),max[0] - min[0])) * size[0]);
should be useful to avoid similar problems. And we should include it.
Do you want to make a PR for this?
Sure. Will submit the pr tomorrow morning.
On Thu, Mar 31, 2022, 00:07 Mingjian Wen @.***> wrote:
Yeah, this has been fixed in the latest release v0.3.3.
The problem in the previous version is that std::numeric_limits
::epsilon() is used as eps to be added to max. Then when we do (max+eps) - min, it got evaluated to 0, instead of std::numeric_limits ::epsilon() due to numerical error. The way we fixed it is by using a larger eps (1e-10 now). But I think some thing like index[0] = static_cast
(((x[0] - min[0]) / std::max(std::numeric_limits ::epsilon(),max[0] - min[0])) * size[0]); should be useful to avoid similar problems. And we should include it. Do you want to make a PR for this?
— Reply to this email directly, view it on GitHub https://github.com/openkim/kliff/issues/43#issuecomment-1084080731, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTZ2D4JUTMP5RQB4CRFLVTVCUXJ5ANCNFSM5SEDGZOA . You are receiving this because you authored the thread.Message ID: @.***>
Josh stumbled upon the bug where for a system where maximum coordinate == minimum coordinate != 0, then there can be cases where following snippet will result in division by zero:
File kliff/neighbor/helper.hpp:96
As then (max + eps) - min == 0.
Reproducible minimal example:
It can be mitigated simply by checking for zero
Or more accurately
Following above changes, above example works correctly.