From e14021bf6929fa1fab11d4c362b966c4d4cb243d Mon Sep 17 00:00:00 2001 From: "Fernando J. Iglesias Garcia" Date: Mon, 8 Apr 2024 14:32:36 +0200 Subject: [PATCH 1/2] Add CoverTree include in unit test. --- test/unit/neighbors.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/unit/neighbors.cpp b/test/unit/neighbors.cpp index c05f331..d98c82b 100644 --- a/test/unit/neighbors.cpp +++ b/test/unit/neighbors.cpp @@ -2,6 +2,9 @@ #include #include +#ifdef TAPKEE_USE_LGPL_COVERTREE +#include +#endif #include "callbacks.hpp" @@ -48,6 +51,7 @@ TEST(Neighbors, BruteDistanceNeighbors) } } +#ifdef TAPKEE_USE_LGPL_COVERTREE TEST(Neighbors, CoverTreeDistanceNeighbors) { typedef std::vector Floats; @@ -83,6 +87,7 @@ TEST(Neighbors, CoverTreeDistanceNeighbors) ASSERT_NE(neighbors_set.find(floats[i + j + 1]), neighbors_set.end()); } } +#endif TEST(Neighbors, BruteKernelNeighbors) { @@ -121,6 +126,7 @@ TEST(Neighbors, BruteKernelNeighbors) } } +#ifdef TAPKEE_USE_LGPL_COVERTREE TEST(Neighbors, CoverTreeKernelNeighbors) { typedef std::vector Floats; @@ -156,3 +162,4 @@ TEST(Neighbors, CoverTreeKernelNeighbors) ASSERT_NE(neighbors_set.find(floats[i + j + 1]), neighbors_set.end()); } } +#endif From ac425b3f77ed0eab1b60d8354a164133b12a47ac Mon Sep 17 00:00:00 2001 From: "Fernando J. Iglesias Garcia" Date: Mon, 8 Apr 2024 15:16:03 +0200 Subject: [PATCH 2/2] Recompute neighbors doubling in case the graph is not connected. --- include/tapkee/neighbors/neighbors.hpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/include/tapkee/neighbors/neighbors.hpp b/include/tapkee/neighbors/neighbors.hpp index 55cdab8..5077e31 100644 --- a/include/tapkee/neighbors/neighbors.hpp +++ b/include/tapkee/neighbors/neighbors.hpp @@ -6,6 +6,7 @@ /* Tapkee includes */ #include +#include #include #ifdef TAPKEE_USE_LGPL_COVERTREE #include @@ -15,6 +16,7 @@ /* End of Tapkee includes */ #include +#include #include #include @@ -190,10 +192,19 @@ Neighbors find_neighbors(NeighborsMethod method, const RandomAccessIterator& beg neighbors = find_neighbors_covertree_impl(begin, end, callback, k); #endif - if (check_connectivity) + if (check_connectivity && !is_connected(begin, end, neighbors)) { - if (!is_connected(begin, end, neighbors)) - LoggingSingleton::instance().message_warning("The neighborhood graph is not connected."); + const std::string message = fmt::format("The neighborhood graph with {} neighbors " + "is not connected. Recomputing with a " + "larger number of neighbors {}.", k, 2 *k); + LoggingSingleton::instance().message_warning(message); + neighbors = find_neighbors(method, begin, end, callback, 2 * k, check_connectivity); + } + else + { + const std::string message = fmt::format("The neighborhood graph with {} neighbors " + "is connected.", k); + LoggingSingleton::instance().message_info(message); } return neighbors; }