From baa90b310cb533921a14fa4a8b5653dfcf7ebeee Mon Sep 17 00:00:00 2001 From: Jonas Jankaitis <111707981+John-194@users.noreply.github.com> Date: Fri, 4 Sep 2026 13:25:59 +0300 Subject: [PATCH] sklearn: fix neighbour cell radius: sqrt(4*dim-3) so all cells that can hold points within eps are visited (sqrt(dim+3) only holds in 2D) --- include/dbscan/grid.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/dbscan/grid.h b/include/dbscan/grid.h index 31870b9..2460b29 100644 --- a/include/dbscan/grid.h +++ b/include/dbscan/grid.h @@ -131,14 +131,15 @@ struct grid { return totalPoints; } + static constexpr floatT nbrHop() {return 1.0000001 * sqrt((floatT)(4 * dim - 3));} + inline cellBuf* nbrCacheFor(int idx, cellT* bait) { // Acquire ensures vector contents are visible if pointer is non-null auto cached = nbrCache[idx].load(std::memory_order_acquire); if (cached) return cached; - floatT hop = sqrt(dim + 3) * 1.0000001; auto fStop = [&](){return false;}; auto fNone = [&](cellT* cell){return false;}; - auto mine = tree->rangeNeighbor(bait, r * hop, fStop, fNone, true, (cellBuf*)nullptr); + auto mine = tree->rangeNeighbor(bait, r * nbrHop(), fStop, fNone, true, (cellBuf*)nullptr); cellBuf* expected = nullptr; if (nbrCache[idx].compare_exchange_strong(expected, mine, std::memory_order_acq_rel, @@ -152,7 +153,7 @@ struct grid { template inline void nghPointMap(floatT* center, func& f) { auto bait = getCell(center);//center must be there - if (!bait) { + if (bait == table->empty || bait < cells || bait >= cells + numCells) { cout << "error, nghPointMap mapped to a non-existent point, abort" << endl; abort();} auto fWrap = [&](cellT* nbr) {