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
44 explicit AutoRangeIndex(const NDArray<T, 2> &points) : m_held(pick(points)) {}
45
54 [[nodiscard]] std::vector<std::vector<std::int32_t>> query(T radius, math::Pool pool) const {
55 return std::visit([&](const auto &idx) { return idx.query(radius, pool); }, m_held);
56 }
57
58private:
60 using Brute = BruteForcePairwise<T>;
61 using Held = std::variant<Tree, Brute>;
62
63 static Held pick(const NDArray<T, 2> &points) {
64 if (points.dim(1) >= bruteForceDimFloor) {
65 return Held(std::in_place_type<Brute>, points);
66 }
67 return Held(std::in_place_type<Tree>, points);
68 }
69
70 Held m_held;
71};
72
73} // 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:92
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:461
std::vector< std::vector< std::int32_t > > query(T radius, math::Pool pool) const
Returns the full radius-neighborhood adjacency from the held backend.
AutoRangeIndex(const NDArray< T, 2 > &points)
Constructs the policy, picking the backend once against points.dim(1).
static constexpr std::size_t bruteForceDimFloor
Dimension threshold at or above which the brute-force backend is selected.
Thin injection wrapper around a BS::light_thread_pool.
Definition thread.h:63