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; } 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