Skip to content

Commit

Permalink
Merge pull request #560 from aprokop/warn_loss_of_precision
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop authored Oct 12, 2022
2 parents 0c49e71 + 4d83a65 commit cca601e
Showing 1 changed file with 20 additions and 0 deletions.
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

0 comments on commit cca601e

Please sign in to comment.