Xped
Loading...
Searching...
No Matches
qarray.hpp
Go to the documentation of this file.
1#ifndef STRAWBERRY_QARRAY
2#define STRAWBERRY_QARRAY
3
5#include <algorithm>
6#include <array>
7#include <iostream>
8#include <limits>
9#include <set>
11
12#include <boost/functional/hash.hpp>
13
14#include "yas/serialize.hpp"
15#include "yas/std_types.hpp"
16
18
19namespace Xped {
20
28template <size_t Nq>
29struct qarray
30{
32 constexpr qarray()
33 {
34 for(size_t q = 0; q < Nq; ++q) { data[q] = 0; }
35 };
36
38 constexpr qarray(const std::array<int, Nq>& in)
39 : data(in){};
40
41 qarray(const std::vector<int>& in)
42 {
43 assert(in.size() == Nq);
44 std::copy(in.begin(), in.end(), data.begin());
45 };
46
48 qarray(std::initializer_list<int> a) { std::copy(a.begin(), a.end(), data.data()); }
49
50 std::array<int, Nq> data;
51
52 int& operator[](size_t i) { return data[i]; }
53 int& operator()(size_t i) { return data[i]; }
54 const int& operator[](size_t i) const { return data[i]; }
55 const int& operator()(size_t i) const { return data[i]; }
56
57 int distance(const qarray<Nq>& other)
58 {
59 std::array<int, Nq> dists;
60 for(size_t i = 0; i < Nq; i++) { dists[i] = abs(this->data[i] - other[i]); }
61 return *std::max_element(std::begin(dists), std::end(dists));
62 }
63
64 friend std::size_t hash_value(const qarray<Nq>& qin)
65 {
66 std::size_t seed = 0;
67 for(size_t q = 0; q < Nq; ++q) { boost::hash_combine(seed, qin.data[q]); }
68
69 return seed;
70 }
71
72 template <typename Ar>
73 void serialize(Ar& ar)
74 {
75 ar& YAS_OBJECT_NVP("qarray", ("data", data));
76 }
77};
78
79template <size_t Nq>
80using qarray2 = std::array<qarray<Nq>, 2>;
81template <size_t Nq>
82using qarray3 = std::array<qarray<Nq>, 3>;
83template <size_t Nq>
84using qarray4 = std::array<qarray<Nq>, 4>;
85
86// "<" and "==" need to be outside of class for map & set, don't ask me why
87template <size_t Nq>
88bool operator==(const qarray<Nq>& lhs, const qarray<Nq>& rhs)
89{
90 return lhs.data == rhs.data;
91}
92template <size_t Nq>
93bool operator!=(const qarray<Nq>& lhs, const qarray<Nq>& rhs)
94{
95 return lhs.data != rhs.data;
96}
97template <size_t Nq>
98bool operator<=(const qarray<Nq>& lhs, const qarray<Nq>& rhs)
99{
100 return lhs.data <= rhs.data;
101}
102template <size_t Nq>
103bool operator>=(const qarray<Nq>& lhs, const qarray<Nq>& rhs)
104{
105 return lhs.data >= rhs.data;
106}
107template <size_t Nq>
108bool operator<(const qarray<Nq>& lhs, const qarray<Nq>& rhs)
109{
110 return lhs.data < rhs.data;
111}
112template <size_t Nq>
113bool operator>(const qarray<Nq>& lhs, const qarray<Nq>& rhs)
114{
115 return lhs.data > rhs.data;
116}
117
119template <size_t Nq>
121{
122 qarray<Nq> aout;
123 transform(a1.data.begin(), a1.data.end(), a2.data.begin(), aout.data.begin(), std::plus<int>());
124 return aout;
125}
126
128template <size_t Nq>
130{
131 qarray<Nq> aout;
132 transform(a1.data.begin(), a1.data.end(), a2.data.begin(), aout.data.begin(), std::minus<int>());
133 return aout;
134}
135
137template <size_t Nq>
138qarray<Nq> operator*(const size_t& alpha, const qarray<Nq>& a)
139{
140 qarray<Nq> aout;
141 for(size_t q = 0; q < Nq; ++q) { aout[q] = alpha * a[q]; }
142 return aout;
143}
144
146template <std::size_t Nq1, std::size_t Nq2>
148{
149 auto new_array = util::join(rhs.data, lhs.data);
151 out.data = new_array;
152 return out;
153}
154
155template <std::size_t Nq1, std::size_t Nq2, std::size_t Nql>
156std::pair<qarray<Nq1>, qarray<Nq2>> disjoin(const qarray<Nql>& large_arr)
157{
158 qarray<Nq1> lhs;
159 memcpy(lhs.data.data(), large_arr.data.data(), Nq1 * sizeof(int));
160 // std::copy(large_arr.data.begin(), large_arr.data.begin() + Nq1, lhs.data.begin());
161 qarray<Nq2> rhs;
162 memcpy(rhs.data.data(), large_arr.data.data() + Nq1, Nq2 * sizeof(int));
163 // std::copy(large_arr.data.begin() + Nq1, large_arr.data.end(), rhs.data.begin());
164 return std::make_pair(lhs, rhs);
165}
166
167template <size_t Nq>
168std::ostream& operator<<(std::ostream& os, const qarray<Nq>& a)
169{
170 os << "(";
171 for(size_t q = 0; q < Nq; ++q) {
172 os << a[q];
173 if(q != Nq - 1) { os << ","; }
174 }
175 os << ")";
176 return os;
177}
178
180// template<size_t Nq>
181// qarray<Nq> qvacuum()
182//{
183// qarray<Nq> aout;
184// for (size_t q=0; q<Nq; ++q) {aout[q] = 0;}
185// return aout;
186//}
187
188template <size_t Nq>
190{
191 qarray<Nq> aout;
192 for(size_t q = 0; q < Nq; ++q) { aout[q] = std::numeric_limits<int>::max(); }
193 return aout;
194}
195
196template <size_t Nq>
198{
199 qarray<Nq> aout;
200 for(size_t q = 0; q < Nq; ++q) { aout[q] = -std::numeric_limits<int>::max(); }
201 return aout;
202}
203
204} // namespace Xped
205#endif
constexpr std::array< T, LL+RL > join(const std::array< T, LL > rhs, const std::array< T, RL > lhs, detail::num_tuple< LLs... >, detail::num_tuple< RLs... >)
Definition: JoinArray.hpp:41
Definition: bench.cpp:62
constexpr qarray< Nq1+Nq2 > join(qarray< Nq1 > rhs, qarray< Nq2 > lhs)
Definition: qarray.hpp:147
qarray< Nq > qminusinf()
Definition: qarray.hpp:197
bool operator>(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.hpp:113
std::array< qarray< Nq >, 4 > qarray4
Definition: qarray.hpp:84
bool operator<=(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.hpp:98
bool operator!=(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.hpp:93
XTensor< TRACK, Scalar, Rank, CoRank, Symmetry > operator-(const Tensor< Scalar, Rank, CoRank, Symmetry, true > &t, Scalar s)
Definition: ADTensor.hpp:428
XTensor< TRACK, Scalar, Rank, CoRank, Symmetry > operator+(const Tensor< Scalar, Rank, CoRank, Symmetry, true > &t, Scalar s)
Definition: ADTensor.hpp:440
XTensor< TRACK, Scalar, Rank, CoRank, Symmetry > operator*(const Tensor< Scalar, Rank, CoRank, Symmetry, true > &t, Scalar s)
Definition: ADTensor.hpp:452
qarray< Nq > qplusinf()
‍**Constructs the vacuum (all quantum numbers equal to zero).*‍/
Definition: qarray.hpp:189
bool operator>=(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.hpp:103
std::ostream & operator<<(std::ostream &os, const FusionTree< depth, Symmetry > &tree)
Definition: FusionTree.hpp:93
std::array< qarray< Nq >, 2 > qarray2
Definition: qarray.hpp:80
std::array< qarray< Nq >, 3 > qarray3
Definition: qarray.hpp:82
bool operator<(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.hpp:108
std::pair< qarray< Nq1 >, qarray< Nq2 > > disjoin(const qarray< Nql > &large_arr)
Definition: qarray.hpp:156
bool operator==(const qarray< Nq > &lhs, const qarray< Nq > &rhs)
Definition: qarray.hpp:88
Definition: qarray.hpp:30
qarray(std::initializer_list< int > a)
Definition: qarray.hpp:48
std::array< int, Nq > data
Definition: qarray.hpp:50
qarray(const std::vector< int > &in)
Definition: qarray.hpp:41
friend std::size_t hash_value(const qarray< Nq > &qin)
Definition: qarray.hpp:64
constexpr qarray()
Definition: qarray.hpp:32
int & operator()(size_t i)
Definition: qarray.hpp:53
constexpr qarray(const std::array< int, Nq > &in)
Definition: qarray.hpp:38
int & operator[](size_t i)
Definition: qarray.hpp:52
const int & operator()(size_t i) const
Definition: qarray.hpp:55
int distance(const qarray< Nq > &other)
Definition: qarray.hpp:57
const int & operator[](size_t i) const
Definition: qarray.hpp:54
void serialize(Ar &ar)
Definition: qarray.hpp:73