1#ifndef KNNCOLLE_FIND_NEAREST_NEIGHBORS_HPP
2#define KNNCOLLE_FIND_NEAREST_NEIGHBORS_HPP
14#ifndef KNNCOLLE_CUSTOM_PARALLEL
32template<
typename Task_,
class Run_>
33void parallelize(
int num_workers, Task_ num_tasks, Run_ run_task_range) {
34#ifndef KNNCOLLE_CUSTOM_PARALLEL
36 subpar::parallelize(num_workers, num_tasks, std::move(run_task_range));
38 KNNCOLLE_CUSTOM_PARALLEL(num_workers, num_tasks, run_task_range);
51template<
typename Index_ =
int,
typename Float_ =
double>
52using NeighborList = std::vector<std::vector<std::pair<Index_, Float_> > >;
71template<
typename Dim_,
typename Index_,
typename Float_>
76 parallelize(num_threads, nobs, [&](
int, Index_ start, Index_ length) ->
void {
78 std::vector<Index_> indices;
79 std::vector<Float_> distances;
80 for (Index_ i = start, end = start + length; i < end; ++i) {
81 sptr->search(i, k, &indices, &distances);
82 int actual_k = indices.size();
83 output[i].reserve(actual_k);
84 for (
int j = 0; j < actual_k; ++j) {
85 output[i].emplace_back(indices[j], distances[j]);
110template<
typename Dim_,
typename Index_,
typename Float_>
113 std::vector<std::vector<Index_> > output(nobs);
115 parallelize(num_threads, nobs, [&](
int, Index_ start, Index_ length) ->
void {
117 for (Index_ i = start, end = start + length; i < end; ++i) {
118 sptr->search(i, k, &(output[i]), NULL);
Interface for prebuilt nearest-neighbor indices.
Interface for prebuilt nearest-neighbor search indices.
Definition Prebuilt.hpp:28
virtual Index_ num_observations() const =0
virtual std::unique_ptr< Searcher< Index_, Float_ > > initialize() const =0
Collection of KNN algorithms.
Definition Bruteforce.hpp:22
std::vector< std::vector< Index_ > > find_nearest_neighbors_index_only(const Prebuilt< Dim_, Index_, Float_ > &index, int k, int num_threads=1)
Definition find_nearest_neighbors.hpp:111
NeighborList< Index_, Float_ > find_nearest_neighbors(const Prebuilt< Dim_, Index_, Float_ > &index, int k, int num_threads=1)
Definition find_nearest_neighbors.hpp:72
std::vector< std::vector< std::pair< Index_, Float_ > > > NeighborList
Definition find_nearest_neighbors.hpp:52
void parallelize(int num_workers, Task_ num_tasks, Run_ run_task_range)
Definition find_nearest_neighbors.hpp:33