62template<
bool keep_index_,
typename Index_,
typename Stat_,
class Output_,
class Cmp_,
class CmpEqual_>
64 if (options.
top == 0) {
65 if constexpr(keep_index_) {
68 std::fill_n(output, n,
false);
73 Stat_ bound = options.
bound;
74 if (
static_cast<size_t>(options.
top) >=
static_cast<size_t>(n)) {
76 for (Index_ i = 0; i < n; ++i) {
77 bool ok = cmp(statistic[i], bound);
78 if constexpr(keep_index_) {
87 if constexpr(keep_index_) {
89 std::iota(output.begin(), output.end(),
static_cast<Index_
>(0));
91 std::fill_n(output, n,
true);
97 std::vector<Index_> semi_sorted(n);
98 std::iota(semi_sorted.begin(), semi_sorted.end(),
static_cast<Index_
>(0));
99 auto cBegin = semi_sorted.begin(), cMid = cBegin + options.
top - 1, cEnd = semi_sorted.end();
100 std::nth_element(cBegin, cMid, cEnd, [&](Index_ l, Index_ r) ->
bool {
101 auto L = statistic[l], R = statistic[r];
109 Stat_ threshold = statistic[semi_sorted[options.
top - 1]];
112 if (options.
use_bound && !cmp(threshold, bound)) {
113 for (Index_ i = 0; i < n; ++i) {
114 bool ok = cmp(statistic[i], bound);
115 if constexpr(keep_index_) {
124 for (Index_ i = 0; i < n; ++i) {
125 bool ok = cmpeq(statistic[i], threshold);
126 if constexpr(keep_index_) {
138 if constexpr(keep_index_) {
139 output.reserve(options.
top);
141 std::fill_n(output, n,
false);
145 Index_ counter = options.
top;
146 while (counter > 0) {
148 auto pos = semi_sorted[counter];
149 if (cmp(statistic[pos], bound)) {
150 if constexpr(keep_index_) {
151 output.push_back(pos);
158 if constexpr(keep_index_) {
159 output.insert(output.end(), semi_sorted.begin(), semi_sorted.begin() + options.
top);
161 for (Index_ i = 0, end = options.
top; i < end; ++i) {
162 output[semi_sorted[i]] =
true;
167 if constexpr(keep_index_) {
168 std::sort(output.begin(), output.end());
187template<
typename Stat_,
typename Bool_>
190 internal::choose_highly_variable_genes<false>(
199 internal::choose_highly_variable_genes<false>(
220template<
typename Bool_ = u
int8_t,
typename Stat_>
242template<
typename Index_,
typename Stat_>
244 std::vector<Index_>
output;
246 internal::choose_highly_variable_genes<true>(
255 internal::choose_highly_variable_genes<true>(
std::vector< Index_ > choose_highly_variable_genes_index(Index_ n, const Stat_ *statistic, const ChooseHighlyVariableGenesOptions &options)
Definition choose_highly_variable_genes.hpp:243
void choose_highly_variable_genes(size_t n, const Stat_ *statistic, Bool_ *output, const ChooseHighlyVariableGenesOptions &options)
Definition choose_highly_variable_genes.hpp:188