Chi-Tech
subsets.cc
Go to the documentation of this file.
1#include "chi_utils.h"
2
3#include <cmath>
4
5#define scdouble static_cast<double>
6
7namespace chi
8{
9
10std::vector<SubSetInfo> MakeSubSets(size_t num_items,
11 size_t desired_num_subsets)
12{
13 std::vector<SubSetInfo> ss_infos;
14 const std::size_t div =
15 std::floor(scdouble(num_items) / scdouble(desired_num_subsets));
16 const std::size_t rem = num_items % desired_num_subsets;
17
18 for (size_t i = 0; i < desired_num_subsets; ++i)
19 ss_infos.push_back({0, 0, div});
20 for (size_t j = 0; j < rem; ++j)
21 ss_infos[j].ss_size += 1;
22
23 size_t check_sum = 0;
24 for (size_t i = 0; i < desired_num_subsets; ++i)
25 {
26 ss_infos[i].ss_begin = check_sum;
27 check_sum += ss_infos[i].ss_size;
28 ss_infos[i].ss_end = check_sum - 1;
29 }
30
31 return ss_infos;
32}
33
34} // namespace chi
std::vector< SubSetInfo > MakeSubSets(size_t num_items, size_t desired_num_subsets)
Definition: subsets.cc:10
#define scdouble
Definition: subsets.cc:5