1 #ifndef MPQC_RANGE_BLOCK_HPP
2 #define MPQC_RANGE_BLOCK_HPP
4 #include "mpqc/range.hpp"
11 const std::vector<size_t> &block) {
12 initialize(dims, block);
15 block_list(
const std::vector<range> &dims,
size_t N) {
17 std::vector<size_t> block(dims.size(), 1);
18 for (
size_t i = 0; i < dims.size(); ++i) {
19 block[i] = std::min<size_t>(dims[i].size(), N);
23 initialize(dims, block);
30 std::vector<range> operator[](
size_t index)
const {
31 MPQC_ASSERT(index < size_);
32 size_t N = dims_.size();
33 std::vector<size_t> t(N);
34 for (
size_t i = N; i > 0; ) {
36 t[i] = index/strides_[i];
37 index = index%strides_[i];
40 for (
size_t i = 0; i < N; ++i) {
41 int begin = t[i]*block_[i];
42 int end = std::min<int>(begin + block_[i], *dims_[i].end());
43 r.push_back(
range(begin, end));
49 std::vector<range> dims_;
50 std::vector<size_t> block_;
51 std::vector<size_t> strides_;
54 void initialize(
const std::vector<range> &dims,
55 const std::vector<size_t> &block) {
58 size_t N = dims_.size();
60 for (
size_t i = 0; i < N; ++i) {
61 strides_.push_back(size_);
62 size_ *= (dims_[i].size() + block_[i] + 1)/block_[i];
69 #endif // MPQC_RANGE_BLOCK_HPP