scran
C++ library for basic single-cell RNA-seq analyses
Loading...
Searching...
No Matches
subset_vector.hpp
Go to the documentation of this file.
1#ifndef SUBSET_VECTOR_HPP
2#define SUBSET_VECTOR_HPP
3
4#include "macros.hpp"
5
11namespace scran {
12
26template<bool retain, class Vector, typename Subset>
27Vector subset_vector(const Vector& vec, const Subset* sub) {
28 int n = 0;
29 for (size_t i = 0; i < vec.size(); ++i) {
30 if (sub[i]) {
31 ++n;
32 }
33 }
34
35 if constexpr(!retain) {
36 n = vec.size() - n;
37 }
38
39 Vector output(n);
40 size_t counter = 0;
41 for (size_t i = 0; i < vec.size(); ++i) {
42 if constexpr(retain) {
43 if (sub[i]) {
44 output[counter] = vec[i];
45 ++counter;
46 }
47 } else {
48 if (!sub[i]) {
49 output[counter] = vec[i];
50 ++counter;
51 }
52 }
53 }
54
55 return output;
56}
57
58}
59
60#endif
Set common macros used through libscran.
Functions for single-cell RNA-seq analyses.
Definition AggregateAcrossCells.hpp:18
Vector subset_vector(const Vector &vec, const Subset *sub)
Definition subset_vector.hpp:27