MPQC  3.0.0-alpha
block.hpp
1 #ifndef MPQC_RANGE_BLOCK_HPP
2 #define MPQC_RANGE_BLOCK_HPP
3 
4 #include "mpqc/range.hpp"
5 
6 namespace mpqc {
7 
9 
10  block_list(const std::vector<range> &dims,
11  const std::vector<size_t> &block) {
12  initialize(dims, block);
13  }
14 
15  block_list(const std::vector<range> &dims, size_t N) {
16  MPQC_ASSERT(N > 0);
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);
20  N /= dims[i].size();
21  if (!N) break;
22  }
23  initialize(dims, block);
24  }
25 
26  size_t size() const {
27  return size_;
28  }
29 
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; ) {
35  --i;
36  t[i] = index/strides_[i];
37  index = index%strides_[i];
38  }
39  std::vector<range> r;
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));
44  }
45  return r;
46  }
47 
48  private:
49  std::vector<range> dims_;
50  std::vector<size_t> block_;
51  std::vector<size_t> strides_;
52  size_t size_;
53 
54  void initialize(const std::vector<range> &dims,
55  const std::vector<size_t> &block) {
56  dims_ = dims;
57  block_ = block;
58  size_t N = dims_.size();
59  size_ = 1;
60  for (size_t i = 0; i < N; ++i) {
61  strides_.push_back(size_);
62  size_ *= (dims_[i].size() + block_[i] + 1)/block_[i];
63  }
64  }
65  };
66 
67 } // namespace mpqc
68 
69 #endif // MPQC_RANGE_BLOCK_HPP
mpqc
Contains new MPQC code since version 3.
Definition: integralenginepool.hpp:37
mpqc::range
Definition: range.hpp:23
mpqc::range::block_list
Definition: block.hpp:8

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.