1 |
|
|
/*************************************** |
2 |
|
|
Auteur : Pierre Aubert |
3 |
|
|
Mail : pierre.aubert@lapp.in2p3.fr |
4 |
|
|
Licence : CeCILL-C |
5 |
|
|
****************************************/ |
6 |
|
|
|
7 |
|
|
|
8 |
|
|
#include "PStride.h" |
9 |
|
|
|
10 |
|
|
///Print a vector of size_t |
11 |
|
|
/** @param[out] out : output stream |
12 |
|
|
* @param vec : vector to be printed |
13 |
|
|
*/ |
14 |
|
46 |
void printVecSize(std::ostream & out, const PVecSize & vec){ |
15 |
✓ |
46 |
out << "("; |
16 |
✓ |
92 |
std::string comma(""); |
17 |
✓✓ |
107 |
for(PVecSize::const_iterator it(vec.begin()); it != vec.end(); ++it){ |
18 |
✓✓ |
61 |
out << comma << (*it); |
19 |
✓ |
61 |
comma = ", "; |
20 |
|
|
} |
21 |
✓ |
46 |
out << ")"; |
22 |
|
46 |
} |
23 |
|
|
|
24 |
|
|
///Constructor of class PStride |
25 |
|
9 |
PStride::PStride(){ |
26 |
✓ |
9 |
updateFullSize(); |
27 |
|
9 |
p_nbVecNeighbour = 1lu; |
28 |
|
9 |
} |
29 |
|
|
|
30 |
|
|
///Constructor of PStride |
31 |
|
|
/** @param vecDimension : vector of number of element of all dimensions |
32 |
|
|
*/ |
33 |
|
2 |
PStride::PStride(const PVecSize & vecDimension) |
34 |
✓ |
2 |
:p_vecDimension(vecDimension) |
35 |
|
|
{ |
36 |
✓ |
2 |
updateFullSize(); |
37 |
|
2 |
p_nbVecNeighbour = 1lu; |
38 |
|
2 |
} |
39 |
|
|
|
40 |
|
|
///Constructor of PStride |
41 |
|
|
/** @param vecDimension : vector of number of element of all dimensions |
42 |
|
|
* @param vecPadding : vector of padding of all dimensions |
43 |
|
|
*/ |
44 |
|
2 |
PStride::PStride(const PVecSize & vecDimension, const PVecSize & vecPadding) |
45 |
✓✓ |
2 |
:p_vecDimension(vecDimension), p_vecPadding(vecPadding) |
46 |
|
|
{ |
47 |
✓ |
2 |
updateFullSize(); |
48 |
|
2 |
p_nbVecNeighbour = 1lu; |
49 |
|
2 |
} |
50 |
|
|
|
51 |
|
|
///Constructor of PStride |
52 |
|
|
/** @param vecDimension : vector of number of element of all dimensions |
53 |
|
|
* @param vecPadding : vector of padding of all dimensions |
54 |
|
|
* @param vecPosition : vector of position in all dimensions |
55 |
|
|
*/ |
56 |
|
1 |
PStride::PStride(const PVecSize & vecDimension, const PVecSize & vecPadding, const PVecSize & vecPosition) |
57 |
✓✓ |
1 |
:p_vecPosition(vecPosition), p_vecDimension(vecDimension), p_vecPadding(vecPadding) |
58 |
|
|
{ |
59 |
✓ |
1 |
updateFullSize(); |
60 |
|
1 |
p_nbVecNeighbour = 1lu; |
61 |
|
1 |
} |
62 |
|
|
|
63 |
|
|
///Copy Constructor of class PStride |
64 |
|
|
/** @param other : PStride we want ot copy |
65 |
|
|
*/ |
66 |
|
6 |
PStride::PStride(const PStride & other){ |
67 |
✓ |
6 |
copyPStride(other); |
68 |
|
6 |
} |
69 |
|
|
|
70 |
|
|
///Destructor of class PStride |
71 |
|
40 |
PStride::~PStride(){ |
72 |
|
|
|
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
///Operator = of class PStride |
76 |
|
|
/** @param other : PStride we want ot copy |
77 |
|
|
* @return copied class PStride |
78 |
|
|
*/ |
79 |
|
6 |
PStride & PStride::operator = (const PStride & other){ |
80 |
|
6 |
copyPStride(other); |
81 |
|
6 |
return *this; |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
///Set the number of vectorial neighbours |
85 |
|
|
/** @param nbVecNeighbour : number of vectorial neighbours |
86 |
|
|
*/ |
87 |
|
1 |
void PStride::setNbVecNeighbour(size_t nbVecNeighbour){ |
88 |
|
1 |
p_nbVecNeighbour = nbVecNeighbour; |
89 |
|
1 |
} |
90 |
|
|
|
91 |
|
|
///Sets the vecPosition of the PStride |
92 |
|
|
/** @param vecPosition : vecPosition of the PStride |
93 |
|
|
*/ |
94 |
|
1 |
void PStride::setVecPosition(const PVecSize & vecPosition){ |
95 |
|
1 |
p_vecPosition = vecPosition; |
96 |
|
1 |
} |
97 |
|
|
|
98 |
|
|
///Sets the vecDimension of the PStride |
99 |
|
|
/** @param vecDimension : vecDimension of the PStride |
100 |
|
|
*/ |
101 |
|
1 |
void PStride::setVecDimension(const PVecSize & vecDimension){ |
102 |
|
1 |
p_vecDimension = vecDimension; |
103 |
|
1 |
updateFullSize(); |
104 |
|
1 |
} |
105 |
|
|
|
106 |
|
|
///Sets the vecPadding of the PStride |
107 |
|
|
/** @param vecPadding : vecPadding of the PStride |
108 |
|
|
*/ |
109 |
|
1 |
void PStride::setVecPadding(const PVecSize & vecPadding){ |
110 |
|
1 |
p_vecPadding = vecPadding; |
111 |
|
1 |
updateFullSize(); |
112 |
|
1 |
} |
113 |
|
|
|
114 |
|
|
///Gets the vecPosition of the PStride |
115 |
|
|
/** @return vecPosition of the PStride |
116 |
|
|
*/ |
117 |
|
1 |
const PVecSize & PStride::getVecPosition() const{ |
118 |
|
1 |
return p_vecPosition; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
///Gets the vecDimension of the PStride |
122 |
|
|
/** @return vecDimension of the PStride |
123 |
|
|
*/ |
124 |
|
2 |
const PVecSize & PStride::getVecDimension() const{ |
125 |
|
2 |
return p_vecDimension; |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
///Gets the vecPadding of the PStride |
129 |
|
|
/** @return vecPadding of the PStride |
130 |
|
|
*/ |
131 |
|
1 |
const PVecSize & PStride::getVecPadding() const{ |
132 |
|
1 |
return p_vecPadding; |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
///Gets the vecFullSize of the PStride |
136 |
|
|
/** @return vecFullSize of the PStride |
137 |
|
|
*/ |
138 |
|
1 |
const PVecSize & PStride::getVecFullSize() const{ |
139 |
|
1 |
return p_vecFullSize; |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
///Get the number of vectorial neighbours |
143 |
|
|
/** @return number of vectorial neighbours |
144 |
|
|
*/ |
145 |
|
1 |
size_t PStride::getNbVecNeighbour() const{ |
146 |
|
1 |
return p_nbVecNeighbour; |
147 |
|
|
} |
148 |
|
|
|
149 |
|
|
///Gets the fullSize of the PStride |
150 |
|
|
/** @return fullSize of the PStride |
151 |
|
|
*/ |
152 |
|
20 |
size_t PStride::getFullSize() const{ |
153 |
|
20 |
return p_fullSize; |
154 |
|
|
} |
155 |
|
|
|
156 |
|
|
///Gets the fullNbElement of the PStride |
157 |
|
|
/** @return fullNbElement of the PStride |
158 |
|
|
*/ |
159 |
|
20 |
size_t PStride::getFullNbElement() const{ |
160 |
|
20 |
return p_fullNbElement; |
161 |
|
|
} |
162 |
|
|
|
163 |
|
|
///Get the number of dimensions |
164 |
|
1 |
size_t PStride::getNbDimension() const{ |
165 |
|
1 |
return p_vecDimension.size(); |
166 |
|
|
} |
167 |
|
|
|
168 |
|
|
///Ostream operator of the PStride |
169 |
|
|
/** @param[out] out : output stream |
170 |
|
|
* @param other : PStride to be printed |
171 |
|
|
* @return output stream |
172 |
|
|
*/ |
173 |
|
20 |
std::ostream & operator << (std::ostream & out, const PStride & other){ |
174 |
|
20 |
out << "PStride(nbDim = " << other.p_vecDimension.size() << ", nbVecNeighbour = " << other.p_nbVecNeighbour << ", fullNbElmt = " << other.p_fullNbElement << ", fullSize = " << other.p_fullSize; |
175 |
✓✓ |
20 |
if(other.p_vecDimension.size() != 0lu){ |
176 |
|
16 |
out << ", dims = "; |
177 |
|
16 |
printVecSize(out, other.p_vecDimension); |
178 |
|
|
} |
179 |
✓✓ |
20 |
if(other.p_vecPadding.size() != 0lu){ |
180 |
|
10 |
out << ", padding = "; |
181 |
|
10 |
printVecSize(out, other.p_vecPadding); |
182 |
|
|
} |
183 |
✓✓ |
20 |
if(other.p_vecFullSize.size() != 0lu){ |
184 |
|
16 |
out << ", fullSize = "; |
185 |
|
16 |
printVecSize(out, other.p_vecFullSize); |
186 |
|
|
} |
187 |
✓✓ |
20 |
if(other.p_vecPosition.size() != 0lu){ |
188 |
|
4 |
out << ", position = "; |
189 |
|
4 |
printVecSize(out, other.p_vecPosition); |
190 |
|
|
} |
191 |
|
20 |
out << ")"; |
192 |
|
20 |
return out; |
193 |
|
|
} |
194 |
|
|
|
195 |
|
|
///Copy Function of class PStride |
196 |
|
|
/** @param other : PStride we want ot copy |
197 |
|
|
*/ |
198 |
|
12 |
void PStride::copyPStride(const PStride & other){ |
199 |
|
12 |
p_vecPosition = other.p_vecPosition; |
200 |
|
12 |
p_vecDimension = other.p_vecDimension; |
201 |
|
12 |
p_vecPadding = other.p_vecPadding; |
202 |
|
12 |
p_vecFullSize = other.p_vecFullSize; |
203 |
|
12 |
p_fullSize = other.p_fullSize; |
204 |
|
12 |
p_fullNbElement = other.p_fullNbElement; |
205 |
|
12 |
p_nbVecNeighbour = other.p_nbVecNeighbour; |
206 |
|
12 |
} |
207 |
|
|
|
208 |
|
|
///Update the full size and the full nb element of the PStride |
209 |
|
16 |
void PStride::updateFullSize(){ |
210 |
|
16 |
bool isDimension(p_vecDimension.size() != 0lu); |
211 |
|
16 |
bool isPadding(p_vecPadding.size() != 0lu); |
212 |
|
16 |
bool isPaddingEqDimension(p_vecDimension.size() == p_vecPadding.size()); |
213 |
✓✓ |
16 |
if(isDimension){ |
214 |
|
6 |
p_fullNbElement = 1lu; |
215 |
✓✓ |
6 |
if(isPadding){ |
216 |
✗✓ |
3 |
if(!isPaddingEqDimension){ |
217 |
|
|
std::runtime_error("PStride::updateFullSize : padding and dimension contains values but not the same number!!!!"); |
218 |
|
|
} |
219 |
|
3 |
p_fullSize = 1lu; |
220 |
|
3 |
p_vecFullSize.resize(p_vecDimension.size()); |
221 |
✓✓ |
7 |
for(size_t i(0lu); i < p_vecDimension.size(); ++i){ |
222 |
|
4 |
size_t dimSize(p_vecDimension[i] + p_vecPadding[i]); |
223 |
|
4 |
p_vecFullSize[i] = dimSize; |
224 |
|
4 |
p_fullNbElement *= p_vecDimension[i]; |
225 |
|
4 |
p_fullSize *= dimSize; |
226 |
|
|
} |
227 |
|
|
}else{ |
228 |
✓✓ |
7 |
for(PVecSize::iterator it(p_vecDimension.begin()); it != p_vecDimension.end(); ++it){ |
229 |
|
4 |
p_fullNbElement *= *it; |
230 |
|
|
} |
231 |
|
3 |
p_vecFullSize = p_vecDimension; |
232 |
|
3 |
p_fullSize = p_fullNbElement; |
233 |
|
|
} |
234 |
|
|
}else{ |
235 |
✓✓ |
10 |
if(isPadding){ |
236 |
|
1 |
p_fullSize = 1lu; |
237 |
✓✓ |
2 |
for(PVecSize::iterator it(p_vecPadding.begin()); it != p_vecPadding.end(); ++it){ |
238 |
|
1 |
p_fullSize *= *it; |
239 |
|
|
} |
240 |
|
|
}else{ |
241 |
|
9 |
p_fullSize = 0lu; |
242 |
|
|
} |
243 |
|
10 |
p_fullNbElement = 0lu; |
244 |
|
|
} |
245 |
|
16 |
} |
246 |
|
|
|
247 |
|
|
|
248 |
|
|
|