Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
Loading...
Searching...
No Matches
auto_range_index.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <variant>
6#include <vector>
7
11#include "clustering/ndarray.h"
12
14
25template <class T> class AutoRangeIndex {
26public:
27#ifdef CLUSTERING_DBSCAN_BRUTE_FORCE_DIM_FLOOR
33 static constexpr std::size_t bruteForceDimFloor = CLUSTERING_DBSCAN_BRUTE_FORCE_DIM_FLOOR;
34#else
36 static constexpr std::size_t bruteForceDimFloor = 16;
37#endif
38
46 explicit AutoRangeIndex(const NDArray<T, 2> &points, math::Pool pool = {})
47 : m_held(pick(points, pool)) {}
48
57 [[nodiscard]] CoreAdjacency query(T radius, std::size_t minPts, math::Pool pool) const {
58 return std::visit([&](const auto &idx) { return idx.query(radius, minPts, pool); }, m_held);
59 }
60
61private:
63 using Brute = BruteForcePairwise<T>;
64 using Held = std::variant<Tree, Brute>;
65
66 static Held pick(const NDArray<T, 2> &points, math::Pool pool) {
67 if (points.dim(1) >= bruteForceDimFloor) {
68 return Held(std::in_place_type<Brute>, points);
69 }
70 return Held(std::in_place_type<Tree>, points, pool);
71 }
72
73 Held m_held;
74};
75
76} // namespace clustering::index
Range-index backend that builds the full eps-neighborhood adjacency in one fused pairwise sweep.
Implements a KDTree data structure.
Definition kdtree.h:93
Represents a multidimensional array (NDArray) of a fixed number of dimensions N and element type T.
Definition ndarray.h:136
size_t dim(std::size_t index) const noexcept
Returns the size of a specific dimension of the NDArray.
Definition ndarray.h:462
AutoRangeIndex(const NDArray< T, 2 > &points, math::Pool pool={})
Constructs the policy, picking the backend once against points.dim(1).
CoreAdjacency query(T radius, std::size_t minPts, math::Pool pool) const
Returns the core-aware radius adjacency from the held backend.
static constexpr std::size_t bruteForceDimFloor
Dimension threshold at or above which the brute-force backend is selected.
Radius-neighborhood adjacency with per-point core flags.
Definition range_query.h:30
Thin compile-time-templated wrapper around the underlying OwnedPool.
Definition thread.h:109