scran_blocks
Blocking utilities for libscran
Loading...
Searching...
No Matches
block_weights.hpp
Go to the documentation of this file.
1#ifndef SCRAN_BLOCKS_BLOCK_WEIGHTS_HPP
2#define SCRAN_BLOCKS_BLOCK_WEIGHTS_HPP
3
9namespace scran_blocks {
10
22enum class WeightPolicy : char { NONE, VARIABLE, EQUAL };
23
32 double lower_bound = 0;
33
38 double upper_bound = 1000;
39};
40
58 if (s < params.lower_bound || s == 0) {
59 return 0;
60 }
61
62 if (s > params.upper_bound) {
63 return 1;
64 }
65
66 return (s - params.lower_bound) / (params.upper_bound - params.lower_bound);
67}
68
83template<typename Size_, typename Weight_>
85 if (policy == WeightPolicy::NONE) {
86 std::copy_n(sizes, num_blocks, weights);
87 } else if (policy == WeightPolicy::EQUAL) {
88 for (size_t s = 0; s < num_blocks; ++s) {
89 weights[s] = sizes[s] > 0;
90 }
91 } else {
92 for (size_t s = 0; s < num_blocks; ++s) {
94 }
95 }
96}
97
110template<typename Weight_ = double, typename Size_>
111std::vector<Weight_> compute_weights(const std::vector<Size_>& sizes, WeightPolicy policy, const VariableWeightParameters& variable) {
112 std::vector<Weight_> output(sizes.size());
113 compute_weights(sizes.size(), sizes.data(), policy, variable, output.data());
114 return output;
115}
116
117}
118
119#endif
Blocking utilities for libscran.
Definition average_vectors.hpp:15
double compute_variable_weight(double s, const VariableWeightParameters &params)
Definition block_weights.hpp:57
void average_vectors(size_t n, std::vector< Stat_ * > in, Output_ *out, bool skip_nan)
Definition average_vectors.hpp:121
void compute_weights(size_t num_blocks, const Size_ *sizes, WeightPolicy policy, const VariableWeightParameters &variable, Weight_ *weights)
Definition block_weights.hpp:84
WeightPolicy
Definition block_weights.hpp:22
Parameters for compute_variable_weight().
Definition block_weights.hpp:27
double lower_bound
Definition block_weights.hpp:32
double upper_bound
Definition block_weights.hpp:38