Skip to content

Commit

Permalink
OK, so now we know there are tiny differences between distances
Browse files Browse the repository at this point in the history
computed by ANN's distance function and geogram distance function, may
come from some automatic FP optimizations triggered by default by Mac
clang. So we have a solution that works with a tiny tolerance but I do
not like it. Here I'm just trying to recompute geogram's distances using
ANN's distance functions before comparing. We shall see...
  • Loading branch information
BrunoLevy committed Jun 12, 2024
1 parent 7fcdac8 commit 1587fcd
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/tests/test_nn_search/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,22 @@ int main(int argc, char** argv) {

bool has_mismatch = false;

for(index_t j = 0; j < nb_neigh; ++j) {
// Recompute distance between i and nearest neighbors computed by geogram using
// ANN's distance function, because there can be tiny differences if the compiler
// does not optimize both functions the same way (happens on Mac/M1)
for(index_t j=0; j < nb_neigh; ++j) {
index_t nn = neigh2[j];
sq_dist2[j] = annDist(
M.vertices.dimension(), M.vertices.point_ptr(i), M.vertices.point_ptr(nn)
);
}

for(index_t j=0; j < nb_neigh; ++j) {
// Added tolerance: on Mac/M1 we got tiny differences,
// I think it is doing auto FMA here and there, to be
// checked.
if(::fabs(sq_dist1[j] - sq_dist2[j]) > 1e-6) {
if(sq_dist1[j] != sq_dist2[j]) {
// if(::fabs(sq_dist1[j] - sq_dist2[j]) > 1e-6) {
has_mismatch = true;
match = false;
Logger::err("Mismatch") << i << "[" << j << "]"
Expand Down

0 comments on commit 1587fcd

Please sign in to comment.