VMPS++
Loading...
Searching...
No Matches
qarray.h
Go to the documentation of this file.
1#ifndef STRAWBERRY_QARRAY
2#define STRAWBERRY_QARRAY
3
5#include <iostream>
6#include <algorithm>
7#include <array>
8#include <set>
9#include <limits>
11
12#include "NestedLoopIterator.h"
13#include "JoinArray.h"
14
24template<size_t Nq>
25struct qarray
26{
28 constexpr qarray() {for (size_t q=0; q<Nq; ++q) {data[q] = 0;}};
29
31 constexpr qarray(const std::array<int,Nq> &in) : data(in) {};
32
34 qarray (std::initializer_list<int> a) {copy(a.begin(), a.end(), data.data());}
35
36 std::array<int,Nq> data;
37
38 int &operator[] (size_t i) {return data[i];}
39 int &operator() (size_t i) {return data[i];}
40 const int &operator[] (size_t i) const {return data[i];}
41 const int &operator() (size_t i) const {return data[i];}
42
43 int distance(const qarray<Nq>& other)
44 {
45 array<int,Nq> dists;
46 for(size_t i=0; i<Nq; i++) { dists[i] = abs(this->data[i] - other[i]); }
47 return *std::max_element(std::begin(dists), std::end(dists));
48 }
49};
50
51template<size_t Nq> using qarray2 = std::array<qarray<Nq>,2>;
52template<size_t Nq> using qarray3 = std::array<qarray<Nq>,3>;
53template<size_t Nq> using qarray4 = std::array<qarray<Nq>,4>;
54
55// "<" and "==" need to be outside of class for map & set, don't ask me why
56template<size_t Nq> bool operator== (const qarray<Nq>& lhs, const qarray<Nq>& rhs) {return lhs.data == rhs.data;}
57template<size_t Nq> bool operator!= (const qarray<Nq>& lhs, const qarray<Nq>& rhs) {return lhs.data != rhs.data;}
58template<size_t Nq> bool operator<= (const qarray<Nq>& lhs, const qarray<Nq>& rhs) {return lhs.data <= rhs.data;}
59template<size_t Nq> bool operator>= (const qarray<Nq>& lhs, const qarray<Nq>& rhs) {return lhs.data >= rhs.data;}
60template<size_t Nq> bool operator< (const qarray<Nq>& lhs, const qarray<Nq>& rhs) {return lhs.data < rhs.data;}
61template<size_t Nq> bool operator> (const qarray<Nq>& lhs, const qarray<Nq>& rhs) {return lhs.data > rhs.data;}
62
64template<size_t Nq>
66{
67 qarray<Nq> aout;
68 transform(a1.data.begin(),a1.data.end(), a2.data.begin(), aout.data.begin(), std::plus<int>());
69 return aout;
70}
71
73template<size_t Nq>
75{
76 qarray<Nq> aout;
77 transform(a1.data.begin(),a1.data.end(), a2.data.begin(), aout.data.begin(), std::minus<int>());
78 return aout;
79}
80
82template<size_t Nq>
83qarray<Nq> operator* (const size_t &alpha, const qarray<Nq> &a)
84{
85 qarray<Nq> aout;
86 for (size_t q=0; q<Nq; ++q)
87 {
88 aout[q] = alpha*a[q];
89 }
90 return aout;
91}
92
94template<std::size_t Nq1, std::size_t Nq2>
96{
97 auto new_array = thirdparty::join(rhs.data, lhs.data);
99 out.data = new_array;
100 return out;
101}
102
103template<std::size_t Nq1, std::size_t Nq2, std::size_t Nql>
104std::pair<qarray<Nq1>, qarray<Nq2> > disjoin(const qarray<Nql>& large_arr)
105{
106 qarray<Nq1> lhs;
107 std::copy(large_arr.data.begin(),large_arr.data.begin()+Nq1,lhs.data.begin());
108 qarray<Nq2> rhs;
109 std::copy(large_arr.data.begin()+Nq1,large_arr.data.end(),rhs.data.begin());
110 return make_pair(lhs,rhs);
111}
112
113template<size_t Nq>
114std::ostream& operator<< (std::ostream& os, const qarray<Nq> &a)
115{
116 os << "(";
117 for (size_t q=0; q<Nq; ++q)
118 {
119 os << a[q];
120 if (q!=Nq-1) {os << ",";}
121 }
122 os << ")";
123 return os;
124}
125
127//template<size_t Nq>
128//qarray<Nq> qvacuum()
129//{
130// qarray<Nq> aout;
131// for (size_t q=0; q<Nq; ++q) {aout[q] = 0;}
132// return aout;
133//}
134
135template<size_t Nq>
137{
138 qarray<Nq> aout;
139 for (size_t q=0; q<Nq; ++q) {aout[q] = numeric_limits<int>::max();}
140 return aout;
141}
142
143template<size_t Nq>
145{
146 qarray<Nq> aout;
147 for (size_t q=0; q<Nq; ++q) {aout[q] = -numeric_limits<int>::max();}
148 return aout;
149}
150
151#endif
std::array< qarray< Nq >, 2 > qarray2
Definition: qarray.h:51
bool operator>(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.h:61
bool operator<(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.h:60
qarray< Nq > qminusinf()
Definition: qarray.h:144
qarray< Nq > operator+(const qarray< Nq > &a1, const qarray< Nq > &a2)
Definition: qarray.h:65
std::array< qarray< Nq >, 3 > qarray3
Definition: qarray.h:52
bool operator<=(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.h:58
bool operator>=(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.h:59
bool operator!=(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.h:57
constexpr qarray< Nq1+Nq2 > join(qarray< Nq1 > rhs, qarray< Nq2 > lhs)
Definition: qarray.h:95
std::array< qarray< Nq >, 4 > qarray4
Definition: qarray.h:53
std::pair< qarray< Nq1 >, qarray< Nq2 > > disjoin(const qarray< Nql > &large_arr)
Definition: qarray.h:104
qarray< Nq > qplusinf()
‍**Constructs the vacuum (all quantum numbers equal to zero).*‍/
Definition: qarray.h:136
qarray< Nq > operator-(const qarray< Nq > &a1, const qarray< Nq > &a2)
Definition: qarray.h:74
bool operator==(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.h:56
std::ostream & operator<<(std::ostream &os, const qarray< Nq > &a)
Definition: qarray.h:114
qarray< Nq > operator*(const size_t &alpha, const qarray< Nq > &a)
Definition: qarray.h:83
Definition: qarray.h:26
std::array< int, Nq > data
Definition: qarray.h:36
constexpr qarray(const std::array< int, Nq > &in)
Definition: qarray.h:31
int distance(const qarray< Nq > &other)
Definition: qarray.h:43
int & operator()(size_t i)
Definition: qarray.h:39
int & operator[](size_t i)
Definition: qarray.h:38
constexpr qarray()
Definition: qarray.h:28
qarray(std::initializer_list< int > a)
Definition: qarray.h:34