Skip to content

Commit

Permalink
test_nn_search:
Browse files Browse the repository at this point in the history
- fixed ANN wrapper for GARGANTUA mode (then we need to convert indices)
- testing again what happens if we recompute distances with ANN's
  function for MacOS/M1: can we get rid of the tolerance ?
  • Loading branch information
BrunoLevy committed Jun 13, 2024
1 parent f91da62 commit 9b97dbd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
14 changes: 10 additions & 4 deletions src/tests/test_nn_search/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ int main(int argc, char** argv) {
for(index_t i = 0; i < M.vertices.nb(); ++i) {
const double* q = M.vertices.point_ptr(i);

neigh1.assign(nb_neigh,NO_INDEX);
sq_dist1.assign(nb_neigh,0.0);
neigh2.assign(nb_neigh,NO_INDEX);
sq_dist2.assign(nb_neigh,0.0);

if(by_index) {
Expand All @@ -149,6 +151,12 @@ int main(int argc, char** argv) {
nb_neigh, q, neigh2.data(), sq_dist2.data()
);
}

for(index_t j=0; j < nb_neigh; ++j) {
//std::cerr << i << " " << j << " " << neigh1[j] << " " << neigh2[j] << std::endl;
geo_assert(neigh1[j] != NO_INDEX);
geo_assert(neigh2[j] != NO_INDEX);
}

bool has_mismatch = false;

Expand All @@ -158,21 +166,19 @@ int main(int argc, char** argv) {
//
// --> Did not work, NOT UNDERSTOOD YET (probably need to play with compilation flags)
// --> Seems that indices neigh2[] are random
/*
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) {
if(sq_dist1[j] != sq_dist2[j]) {
has_mismatch = true;
match = false;
Logger::err("Mismatch") << i << "[" << j << "]"
Expand Down
9 changes: 8 additions & 1 deletion src/tests/test_nn_search/nn_search_ANN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,18 @@ namespace GEO {
index_t* neighbors,
double* neighbors_sq_dist
) const {
// In Gargantua mode, index_t is 64 bits, and ANNidx is always 32 bits, so
// we need to allocate space for ANN indices, then convert and copy them
// to client's neighbors array.
ANNidxArray ann_neighbors = ANNidxArray(alloca(sizeof(ANNidx)*nb_neighbors));
ann_tree_->annkSearch(
const_cast<double*>(query_point),
int(nb_neighbors), (ANNidxArray) neighbors, neighbors_sq_dist,
int(nb_neighbors), ann_neighbors, neighbors_sq_dist,
(exact_ ? 0.0 : 0.1)
);
for(index_t i=0; i<nb_neighbors; ++i) {
neighbors[i] = index_t(ann_neighbors[i]);
}
}

NearestNeighborSearch_ANN::~NearestNeighborSearch_ANN() {
Expand Down

0 comments on commit 9b97dbd

Please sign in to comment.