scran
C++ library for basic single-cell RNA-seq analyses
Loading...
Searching...
No Matches
vector_to_pointers.hpp
Go to the documentation of this file.
1#ifndef VECTOR_TO_POINTERS
2#define VECTOR_TO_POINTERS
3
4#include "macros.hpp"
5
6#include <vector>
7
14namespace scran {
15
25template<typename T>
26std::vector<T*> vector_to_pointers(std::vector<std::vector<T> >& input) {
27 std::vector<T*> output(input.size());
28 auto oIt = output.begin();
29 for (auto& i : input) {
30 *oIt = i.data();
31 ++oIt;
32 }
33 return output;
34}
35
44template<typename T>
45std::vector<const T*> vector_to_pointers(const std::vector<std::vector<T> >& input) {
46 std::vector<const T*> output(input.size());
47 auto oIt = output.begin();
48 for (auto& i : input) {
49 *oIt = i.data();
50 ++oIt;
51 }
52 return output;
53}
54
63template<typename T>
64std::vector<std::vector<T*> > vector_to_pointers(std::vector<std::vector<std::vector<T> > >& input) {
65 std::vector<std::vector<T*> > output;
66 output.reserve(input.size());
67 for (auto& current : input) {
68 output.emplace_back(vector_to_pointers(current));
69 }
70 return output;
71}
72
77// Convenience method to get the pointers if each middle vector contains exactly one inner vector.
78// This allows us to create pointer vectors in the same format as the first vector_to_pointers overload.
79template<typename T>
80std::vector<T*> vector_to_front_pointers(std::vector<std::vector<std::vector<T> > >& input) {
81 std::vector<T*> ptrs;
82 ptrs.reserve(input.size());
83 for (auto& current : input) {
84 ptrs.push_back(current.front().data()); // first vector from each element.
85 }
86 return ptrs;
87}
88
93}
94
95#endif
Set common macros used through libscran.
Functions for single-cell RNA-seq analyses.
Definition AggregateAcrossCells.hpp:18
std::vector< T * > vector_to_pointers(std::vector< std::vector< T > > &input)
Definition vector_to_pointers.hpp:26