mnncorrect
Batch correction with mutual nearest neighbors
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1#ifndef MNNCORRECT_UTILS_HPP
2#define MNNCORRECT_UTILS_HPP
3
4#include <vector>
5#include <algorithm>
6#include <memory>
7#include <cstddef>
8
10
11#ifndef MNNCORRECT_CUSTOM_PARALLEL
12#include "subpar/subpar.hpp"
13#endif
14
20namespace mnncorrect {
21
25typedef std::size_t BatchIndex;
26
42enum class MergePolicy : char { INPUT, SIZE, VARIANCE, RSS };
43
56template<typename Task_, class Run_>
57void parallelize(int num_workers, Task_ num_tasks, Run_ run_task_range) {
58#ifndef MNNCORRECT_CUSTOM_PARALLEL
59 // Methods could allocate or throw, so nothrow_ = false is safest.
60 subpar::parallelize_range<false>(num_workers, num_tasks, std::move(run_task_range));
61#else
62 MNNCORRECT_CUSTOM_PARALLEL(num_workers, num_tasks, run_task_range);
63#endif
64}
65
69namespace internal {
70
71template<typename Index_, typename Distance_>
72using NeighborSet = std::vector<std::vector<std::pair<Index_, Distance_> > >;
73
74template<typename Index_, typename Float_>
75struct Corrected {
76 Corrected() = default;
77 Corrected(std::unique_ptr<knncolle::Prebuilt<Index_, Float_, Float_> > index, std::vector<Index_> ids) : index(std::move(index)), ids(std::move(ids)) {}
78 std::unique_ptr<knncolle::Prebuilt<Index_, Float_, Float_> > index;
79 std::vector<Index_> ids;
80};
81
82template<typename Index_, typename Float_>
83struct BatchInfo {
84 Index_ offset, num_obs;
85 std::unique_ptr<knncolle::Prebuilt<Index_, Float_, Float_> > index;
86 std::vector<Corrected<Index_, Float_> > extras;
87};
88
89}
94}
95
96#endif
Batch correction with mutual nearest neighbors.
Definition utils.hpp:20
void parallelize(int num_workers, Task_ num_tasks, Run_ run_task_range)
Definition utils.hpp:57
MergePolicy
Definition utils.hpp:42
std::size_t BatchIndex
Definition utils.hpp:25