Xped
Loading...
Searching...
No Matches
iPEPSIterator.hpp
Go to the documentation of this file.
1#ifndef XPED_IPEPS_ITERATOR_HPP_
2#define XPED_IPEPS_ITERATOR_HPP_
3
4#include <iterator>
5
6#include <boost/iterator/iterator_facade.hpp>
7
10
11namespace Xped {
12
13template <typename Scalar, typename Symmetry, bool ENABLE_AD>
14class iPEPSIterator : public boost::iterator_facade<iPEPSIterator<Scalar, Symmetry, ENABLE_AD>, Scalar*, boost::forward_traversal_tag, Scalar>
15{
16public:
18 : data(nullptr)
19 {}
20
22 bool ITER_GRAD = false,
23 std::size_t outer_num = 0,
24 std::size_t elem_num = 0)
25 : data(data_in)
26 , ITER_GRAD(ITER_GRAD)
27 , outer_num(outer_num)
28 , elem_num(elem_num)
29 {
30 if constexpr(not ENABLE_AD) { assert(ITER_GRAD == false); }
31 }
32
33private:
35
36 void increment()
37 {
38 if(outer_num == data->size() - 1 and elem_num == data->at(outer_num).plainSize() - 1) {
39 outer_num = data->size();
40 elem_num = 0;
41 return;
42 }
43 if(elem_num < data->at(outer_num).plainSize() - 1)
44 ++elem_num;
45 else {
46 ++outer_num;
47 elem_num = 0;
48 }
49 }
50
51 bool equal(iPEPSIterator<Scalar, Symmetry, ENABLE_AD> const& other) const
52 {
53 return (this->outer_num == other.outer_num and this->elem_num == other.elem_num);
54 }
55
56 Scalar dereference() const
57 {
58 if constexpr(ENABLE_AD) {
59 auto beg = ITER_GRAD ? data->at(outer_num).cgradbegin() : data->at(outer_num).cbegin();
60 std::advance(beg, elem_num);
61 return *beg;
62 } else {
63 auto beg = data->at(outer_num).cbegin();
64 std::advance(beg, elem_num);
65 return *beg;
66 }
67 }
68
69 TMatrix<Tensor<Scalar, 2, 3, Symmetry, ENABLE_AD>>* data;
70 bool ITER_GRAD = false;
71 std::size_t outer_num = 0;
72 std::size_t elem_num = 0;
73};
74
75} // namespace Xped
76#endif
Definition: Tensor.hpp:40
Definition: iPEPSIterator.hpp:15
iPEPSIterator()
Definition: iPEPSIterator.hpp:17
iPEPSIterator(TMatrix< Tensor< Scalar, 2, 3, Symmetry, ENABLE_AD > > *data_in, bool ITER_GRAD=false, std::size_t outer_num=0, std::size_t elem_num=0)
Definition: iPEPSIterator.hpp:21
friend class boost::iterator_core_access
Definition: iPEPSIterator.hpp:34
double Scalar
Definition: Heisenberg.cpp:5
Definition: bench.cpp:62
Definition: TMatrix.hpp:13