Repository navigation
Expand file tree
/
Copy pathProjResultContainers.h
More file actions
182 lines (144 loc) · 5.34 KB
/
Copy pathProjResultContainers.h
File metadata and controls
182 lines (144 loc) · 5.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#ifndef SROTHMAN_EEC_PROJ_CONTAINERS_H
#define SROTHMAN_EEC_PROJ_CONTAINERS_H
#include "usings.h"
#include <vector>
#include <numeric>
#include <boost/multi_array.hpp>
namespace EEC{
template <typename T>
class ProjVectorContainer;
class ProjArrayContainer{
public:
using data_t = std::vector<double>;
using TYPE = unsigned;
constexpr static bool SHOULD_BIN = true;
constexpr static bool IS_ARRAY = true;
ProjArrayContainer() :
nR(0),
data() {}
ProjArrayContainer(const size_t nR) :
nR(nR),
data(nR, 0.0) {}
ProjArrayContainer(ProjArrayContainer&& other) :
nR(other.nR),
data(std::move(other.data)) {}
ProjArrayContainer(const ProjArrayContainer& other) :
nR(other.nR),
data(other.data) {}
ProjArrayContainer(const ProjVectorContainer<unsigned>& other);
void fill(unsigned iR, double wt) noexcept{
data[iR] += wt;
}
const data_t& get_data() const noexcept{
return data;
}
double total_weight() const noexcept {
return std::accumulate(data.begin(), data.end(), 0.0);
}
ProjArrayContainer& operator+=(const ProjArrayContainer& other) noexcept{
std::transform(data.begin(), data.end(),
other.data.begin(), data.begin(),
std::plus<double>());
return *this;
}
ProjArrayContainer& operator+=(const ProjVectorContainer<unsigned> other) noexcept;
template <class OtherContainer>
ProjArrayContainer operator+(const OtherContainer& other) const noexcept{
ProjArrayContainer result(*this);
result += other;
return result;
}
ProjArrayContainer& operator-=(const ProjArrayContainer& other) noexcept{
std::transform(data.begin(), data.end(),
other.data.begin(), data.begin(),
std::minus<double>());
return *this;
}
ProjArrayContainer& operator-=(const ProjVectorContainer<unsigned>& other) noexcept;
template <class OtherContainer>
ProjArrayContainer operator-(const OtherContainer& other) const noexcept{
ProjArrayContainer result(*this);
result -= other;
return result;
}
bool operator==(const ProjArrayContainer& other) const noexcept{
return std::equal(data.begin(), data.end(),
other.data.begin(),
[](double a, double b){
return std::abs(a - b) < 1e-6;
});
}
bool operator==(const ProjVectorContainer<unsigned>& other) const noexcept {
return *this== ProjArrayContainer(other);
}
const size_t nR;
private:
data_t data;
};
template <typename T>
class ProjVectorContainer{
public:
struct entry{
T iR;
double wt;
entry(T iR, double wt) noexcept :
iR(iR), wt(wt) {}
};
using data_t = std::vector<entry>;
using TYPE = T;
constexpr static bool SHOULD_BIN = std::is_same<T, unsigned>::value;
constexpr static bool IS_ARRAY = false;
ProjVectorContainer(const size_t nR) :
nR(nR){
data.reserve(100);
}
ProjVectorContainer() :
ProjVectorContainer(0) {}
ProjVectorContainer(ProjVectorContainer&& other) :
nR(other.nR),
data(std::move(other.data)) {}
ProjVectorContainer(const ProjVectorContainer& other) :
nR(other.nR),
data(other.data) {}
void fill(T iR, double wt) noexcept{
data.emplace_back(iR, wt);
}
ProjVectorContainer<T>& operator+=(const ProjVectorContainer<T>& other) noexcept {
data.insert(data.end(),
other.data.begin(),
other.data.end());
return *this;
}
template <class OtherContainer>
ProjVectorContainer<T> operator+(const OtherContainer& other) const noexcept {
ProjVectorContainer<T> result(*this);
result += other;
return result;
}
template <class OtherContainer>
ProjArrayContainer operator-(const OtherContainer& other) const noexcept {
ProjArrayContainer result(*this);
result -= other;
return result;
}
bool operator==(const ProjVectorContainer& other) const noexcept{
return ProjArrayContainer(*this) == ProjArrayContainer(other);
}
bool operator==(const ProjArrayContainer& other) const noexcept{
return ProjArrayContainer(*this) == other;
}
const data_t& get_data() const noexcept{
return data;
}
double total_weight() const noexcept {
return std::accumulate(data.begin(), data.end(), 0.0,
[](double sum, const entry& e) {
return sum + e.wt;
});
}
const size_t nR;
private:
data_t data;
};
};
#endif