#include "DropletUtils.h" SEXP group_cells (SEXP cells, SEXP gems) { BEGIN_RCPP Rcpp::StringVector Cells(cells); Rcpp::IntegerVector Gems(gems); if (Cells.size()!=Gems.size()) { throw std::runtime_error("cell and gem ID vectors should be the same length"); } // Figuring out the order (using a stable_sort for an easier comparison to downsampleMatrix in test-downsample.R). Rcpp::IntegerVector output(Cells.size()); std::iota(output.begin(), output.end(), 0); std::stable_sort(output.begin(), output.end(), [&](const int& left, const int& right) { if (Cells[left] < Cells[right]) { return true; } else if (Cells[left] > Cells[right]) { return false; } return Gems[left] < Gems[right]; }); // Now figuring out which ones are unique. std::deque unique_Cells; std::deque unique_Gems; std::deque unique_num; if (output.size()) { unique_Cells.push_back(Cells[output[0]]); unique_Gems.push_back(Gems[output[0]]); unique_num.push_back(1); for (size_t i=1; i