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

Throw an exception when potentially losing precision in FDBSCAN-DenseBox #560

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/details/ArborX_DetailsCartesianGrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ struct CartesianGrid
{
auto min = _bounds.minCorner();
decltype(min) max;

// This code may suffer from loss of precision depending on the problem
// bounds and h. We try to detect this case in the constructor.
for (int d = 0; d < DIM; ++d)
{
auto i = cell_index % _n[d];
Expand Down Expand Up @@ -118,6 +121,23 @@ struct CartesianGrid
m /= _n[d - 1];
ARBORX_ASSERT(_n[d] < m);
}

// Catch a potential loss of precision that may happen in cellBox() and can
// lead to wrong results.
//
// The machine precision by itself is not sufficient. In some experiments
// run with a full NGSIM datasets, values below 3 could still produce wrong
// results. This may still not be conservative enough, but all runs passed
// verification when this warning was not triggered.
constexpr auto eps = 5 * std::numeric_limits<float>::epsilon();
for (int d = 0; d < DIM; ++d)
{
if (std::abs(_h[d] / min_corner[d]) < eps)
throw std::runtime_error(
"ArborX exception: FDBSCAN-DenseBox algorithm will experience loss "
"of precision, undetectably producing wrong results. Please switch "
"to using FDBSCAN.");
}
}

Box _bounds;
Expand Down