1#ifndef SCRAN_UTILS_BLOCKING_HPP
2#define SCRAN_UTILS_BLOCKING_HPP
33 return static_cast<size_t>(*std::max_element(ids, ids + length)) + 1;
51template<
typename Output_ =
int,
bool allow_zeros_ = false,
typename Id_>
52std::vector<Output_>
tabulate_ids(
size_t length,
const Id_* ids,
bool allow_zeros =
false) {
55 std::vector<Output_> ids_size(nids);
56 for (
size_t j = 0; j < length; ++j) {
61 for (
auto b : ids_size) {
63 throw std::runtime_error(
"IDs must be 0-based and consecutive with no empty blocks");
147template<
typename Size_>
149 size_t nblocks = sizes.size();
150 std::vector<double> weights;
151 weights.reserve(nblocks);
153 if (policy == WeightPolicy::NONE) {
154 weights.insert(weights.end(), sizes.begin(), sizes.end());
155 }
else if (policy == WeightPolicy::EQUAL) {
156 for (
auto s : sizes) {
157 weights.push_back(s > 0);
160 for (
auto s : sizes) {
Set common macros used through libscran.
Functions for single-cell RNA-seq analyses.
Definition AggregateAcrossCells.hpp:18
double variable_block_weight(double s, const VariableBlockWeightParameters ¶ms)
Definition blocking.hpp:123
size_t count_ids(size_t length, const Id_ *ids)
Definition blocking.hpp:29
std::vector< Output_ > tabulate_ids(size_t length, const Id_ *ids, bool allow_zeros=false)
Definition blocking.hpp:52
std::vector< double > compute_block_weights(const std::vector< Size_ > &sizes, WeightPolicy policy, const VariableBlockWeightParameters ¶m)
Definition blocking.hpp:148
WeightPolicy
Definition blocking.hpp:82
Parameters for variable_block_weight().
Definition blocking.hpp:87
double upper_bound
Definition blocking.hpp:103
constexpr VariableBlockWeightParameters(double l=0, double u=1000)
Definition blocking.hpp:93
double lower_bound
Definition blocking.hpp:98