Commit 7a41b54fce6faba6c1b1700b19f540aaca3102e3
Exists in
master
and in
85 other branches
Merge branch 'rm_7528'
Showing
9 changed files
with
1121 additions
and
1276 deletions
Show diff stats
CMakeLists.txt
... | ... | @@ -127,7 +127,7 @@ add_subdirectory(src/XMLRequest) |
127 | 127 | add_subdirectory(src/SpiceKernel) |
128 | 128 | add_subdirectory(src/amdaXMLRequestorTool) |
129 | 129 | add_subdirectory(src/amdaParameterGenerator) |
130 | -#add_subdirectory(src/expressionParser) | |
130 | +add_subdirectory(src/expressionParser) | |
131 | 131 | add_subdirectory(src/amdaParameterInfo) |
132 | 132 | add_subdirectory(src/amdaGetErrorMsg) |
133 | 133 | add_subdirectory(src/PostProcessing) |
... | ... | @@ -144,7 +144,6 @@ add_subdirectory(src/ParamGetImpl/LocalFileInterface) |
144 | 144 | add_subdirectory(src/ParamGetImpl/ConstantInterface) |
145 | 145 | add_subdirectory(src/InternLib) |
146 | 146 | add_subdirectory(src/ExternLib/Deriv) |
147 | -add_subdirectory(src/ExternLib/Magnitude) | |
148 | 147 | add_subdirectory(src/ExternLib/Morschhauser) |
149 | 148 | add_subdirectory(src/ExternLib/Ram_Presure) |
150 | 149 | add_subdirectory(src/ExternLib/TimeShifted) | ... | ... |
src/ExternLib/Magnitude/CMakeLists.txt deleted
... | ... | @@ -1,23 +0,0 @@ |
1 | - | |
2 | -PROJECT(Magnitude) | |
3 | - | |
4 | -set(LIBRARY_OUTPUT_PATH ${PLUGIN_OUTPUT_PATH}/magnitude) | |
5 | - | |
6 | -include_directories( | |
7 | -) | |
8 | - | |
9 | -#Library configuration | |
10 | -file( | |
11 | - GLOB_RECURSE | |
12 | - source_files | |
13 | - ./* | |
14 | -) | |
15 | - | |
16 | -ADD_LIBRARY( Magnitude SHARED ${source_files} ) | |
17 | - | |
18 | -target_link_libraries( | |
19 | - Magnitude | |
20 | -) | |
21 | - | |
22 | -FILE( GLOB_RECURSE PROJ_HEADERS *.hh ) | |
23 | -INSTALL(FILES ${PROJ_HEADERS} DESTINATION ${LIBRARY_OUTPUT_PATH} PERMISSIONS OWNER_READ GROUP_READ WORLD_READ) |
src/ExternLib/Magnitude/magnitude.cc deleted
... | ... | @@ -1,35 +0,0 @@ |
1 | -/** | |
2 | - * Magnitude.cc | |
3 | - * | |
4 | - * Created on: 31 oct. 2012 | |
5 | - * Author: AKKA IS | |
6 | - */ | |
7 | - | |
8 | -#include "magnitude.hh" | |
9 | - | |
10 | -#include <math.h> | |
11 | - | |
12 | -float magnitude(const std::vector<float>& vec) | |
13 | -{ | |
14 | - return sqrtf(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]); | |
15 | -} | |
16 | - | |
17 | -double magnitude(const std::vector<double>& vec) | |
18 | -{ | |
19 | - return sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]); | |
20 | -} | |
21 | - | |
22 | -long double magnitude(const std::vector<long double>& vec) | |
23 | -{ | |
24 | - return sqrtl(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]); | |
25 | -} | |
26 | - | |
27 | -int magnitude(const std::vector<int>& vec) | |
28 | -{ | |
29 | - return sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]); | |
30 | -} | |
31 | - | |
32 | -short magnitude(const std::vector<short>& vec) | |
33 | -{ | |
34 | - return sqrt(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]); | |
35 | -} |
src/ExternLib/Magnitude/magnitude.hh deleted
... | ... | @@ -1,23 +0,0 @@ |
1 | -/** | |
2 | - * Magnitude.hh | |
3 | - * | |
4 | - * Created on: 31 oct. 2012 | |
5 | - * Author: AKKA IS | |
6 | - */ | |
7 | - | |
8 | -#ifndef MAGNITUDE_HH_ | |
9 | -#define MAGNITUDE_HH_ | |
10 | - | |
11 | -#include <vector> | |
12 | - | |
13 | -/** | |
14 | - * @bried Compute the magnitude of el | |
15 | - * @return sqrtf(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]); | |
16 | - */ | |
17 | -float magnitude(const std::vector<float>& el); | |
18 | - | |
19 | -double magnitude(const std::vector<double>& vec); | |
20 | - | |
21 | -int magnitude(const std::vector<int>& vec); | |
22 | - | |
23 | -#endif /* MAGNITUDE_HH_ */ |
src/ExternLib/Morschhauser/Morschhauser.hh
... | ... | @@ -89,7 +89,7 @@ public: |
89 | 89 | |
90 | 90 | protected: |
91 | 91 | |
92 | - virtual void pushResult(std::vector<DataType> field, DataType magnitude) = 0; | |
92 | + virtual void pushResult(std::vector<DataType> field, DataType magnitude_) = 0; | |
93 | 93 | |
94 | 94 | /** |
95 | 95 | * @brief Input paramter data. |
... | ... | @@ -429,7 +429,7 @@ public: |
429 | 429 | } |
430 | 430 | |
431 | 431 | protected: |
432 | - virtual void pushResult(std::vector<DataType> field, DataType /*magnitude*/) { | |
432 | + virtual void pushResult(std::vector<DataType> field, DataType /*magnitude_*/) { | |
433 | 433 | MorschhauserCommon<DataType, ParamDataSpec<std::vector<DataType> >>::_paramOutput->getDataList().push_back(field); |
434 | 434 | } |
435 | 435 | }; |
... | ... | @@ -453,11 +453,11 @@ public: |
453 | 453 | } |
454 | 454 | |
455 | 455 | protected: |
456 | - virtual void pushResult(std::vector<DataType> /*field*/, DataType magnitude) { | |
457 | - MorschhauserCommon<DataType, ParamDataSpec<DataType>>::_paramOutput->getDataList().push_back(magnitude); | |
456 | + virtual void pushResult(std::vector<DataType> /*field*/, DataType magnitude_) { | |
457 | + MorschhauserCommon<DataType, ParamDataSpec<DataType>>::_paramOutput->getDataList().push_back(magnitude_); | |
458 | 458 | } |
459 | 459 | }; |
460 | 460 | |
461 | 461 | } /* namespace Parameters */ |
462 | 462 | } /* namespace AMDA */ |
463 | -#endif /* MORSCHHAUSER_HH_ */ | |
463 | +#endif /* MORSCHHAUSER_HH_ *// | ... | ... |
src/Parameters/DataTypeMath.hh
... | ... | @@ -13,343 +13,343 @@ |
13 | 13 | #include <cmath> |
14 | 14 | #include "ParamData.hh" |
15 | 15 | |
16 | - inline AMDA::Parameters::LogicalData castToLogicalData(int a) { | |
17 | - if (isNAN(a)) { | |
18 | - return AMDA::Parameters::LogicalData::NaN; | |
19 | - } | |
20 | - return (a >= 1) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False; | |
21 | - } | |
22 | 16 | |
23 | - inline AMDA::Parameters::LogicalData castToLogicalData(AMDA::Parameters::LogicalData a) { | |
24 | - return a; | |
25 | - } | |
17 | +inline AMDA::Parameters::LogicalData castToLogicalData(int a) { | |
18 | + if (isNAN(a)) { | |
19 | + return AMDA::Parameters::LogicalData::NaN; | |
20 | + } | |
21 | + return (a >= 1) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False; | |
22 | +} | |
23 | + | |
24 | +inline AMDA::Parameters::LogicalData castToLogicalData(AMDA::Parameters::LogicalData a) { | |
25 | + return a; | |
26 | +} | |
26 | 27 | |
27 | 28 | /** |
28 | 29 | * @brief Operator And (&&) between LogicalData |
29 | 30 | */ |
30 | - template<typename Type1 , typename Type2> | |
31 | - inline AMDA::Parameters::LogicalData And(Type1 a, Type2 b) { | |
32 | - AMDA::Parameters::LogicalData aa = castToLogicalData(a); | |
33 | - AMDA::Parameters::LogicalData bb = castToLogicalData(b); | |
34 | - AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::NaN; | |
35 | - | |
36 | - if ( aa != AMDA::Parameters::LogicalData::NaN && bb != AMDA::Parameters::LogicalData::NaN) { | |
37 | - res = ((aa==AMDA::Parameters::LogicalData::True) && (bb==AMDA::Parameters::LogicalData::True))?AMDA::Parameters::LogicalData::True:AMDA::Parameters::LogicalData::False; | |
38 | - } | |
39 | - | |
40 | - return res; | |
41 | - } | |
42 | - | |
43 | - /** | |
44 | - * @brief Operator Or (||) between LogicalData | |
45 | - */ | |
46 | - template<typename Type1 , typename Type2> | |
47 | - inline AMDA::Parameters::LogicalData Or(Type1 a, Type2 b) { | |
48 | - AMDA::Parameters::LogicalData aa = castToLogicalData(a); | |
49 | - AMDA::Parameters::LogicalData bb = castToLogicalData(b); | |
50 | - AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::NaN; | |
51 | - | |
52 | - if ( aa != AMDA::Parameters::LogicalData::NaN && bb != AMDA::Parameters::LogicalData::NaN) { | |
53 | - res = (( aa == AMDA::Parameters::LogicalData::True) || (bb == AMDA::Parameters::LogicalData::True))?AMDA::Parameters::LogicalData::True:AMDA::Parameters::LogicalData::False; | |
54 | - } | |
55 | - | |
56 | - return res; | |
57 | - } | |
58 | - | |
59 | - | |
60 | - | |
61 | - /** | |
62 | - * @brief Operator greater_than (>) between LogicalData | |
63 | - */ | |
64 | - template <typename Type1, typename Type2> | |
65 | - AMDA::Parameters::LogicalData greater_than(Type1 a, Type2 b) { | |
66 | - AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::True; | |
67 | - if ( std::isfinite(a) && std::isfinite(b)) { | |
68 | - res = (a>b)?AMDA::Parameters::LogicalData::True:AMDA::Parameters::LogicalData::False; | |
69 | - } else { | |
70 | - res = AMDA::Parameters::LogicalData::NaN; | |
71 | - } | |
72 | - return res; | |
73 | - } | |
74 | - | |
75 | - | |
76 | - /** | |
77 | - * @brief Operator greater_than (>) between table of LogicalData | |
78 | - */ | |
79 | - template<typename Type1, typename Type2> | |
80 | - std::vector<AMDA::Parameters::LogicalData> greater_than(std::vector<Type1> a, | |
81 | - std::vector<Type2> b) { | |
82 | - std::vector<AMDA::Parameters::LogicalData> r; | |
83 | - if (a.size() != b.size()) { | |
84 | - BOOST_THROW_EXCEPTION( | |
85 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Logical comparison between two vector of different size")); | |
86 | - } | |
87 | - | |
88 | - for (unsigned int i = 0; i < a.size(); ++i) { | |
89 | - r.push_back(greater_than(a[i], b[i])); | |
90 | - } | |
91 | - return r; | |
92 | - } | |
93 | - | |
94 | - /** | |
95 | - * @brief Operator lower_than (<) between table of LogicalData | |
96 | - */ | |
97 | - template <typename Type1, typename Type2> | |
98 | - AMDA::Parameters::LogicalData lower_than(Type1 a, Type2 b) { | |
99 | - AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::True; | |
100 | - if ( std::isfinite(a) && std::isfinite(b)) { | |
101 | - res = (a<b)?AMDA::Parameters::LogicalData::True:AMDA::Parameters::LogicalData::False; | |
102 | - } else { | |
103 | - res = AMDA::Parameters::LogicalData::NaN; | |
104 | - } | |
105 | - return res; | |
106 | - } | |
107 | - | |
108 | - /** | |
109 | - * @brief Operator lower_than (<) between table of LogicalData | |
110 | - */ | |
111 | - template<typename Type1, typename Type2> | |
112 | - std::vector<AMDA::Parameters::LogicalData> lower_than(std::vector<Type1> a, | |
113 | - std::vector<Type2> b) { | |
114 | - std::vector<AMDA::Parameters::LogicalData> r; | |
115 | - if (a.size() != b.size()) { | |
116 | - BOOST_THROW_EXCEPTION( | |
117 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Logical comparison between two vector of different size")); | |
118 | - } | |
119 | - | |
120 | - for (unsigned int i = 0; i < a.size(); ++i) { | |
121 | - r.push_back(lower_than(a[i], b[i])); | |
122 | - } | |
123 | - return r; | |
124 | - } | |
125 | - | |
126 | - | |
127 | - | |
128 | - /** | |
129 | - * @brief Operator * between two scalars, one is LogicalData | |
130 | - */ | |
131 | - template <typename Type> | |
132 | - Type operator *(Type a, AMDA::Parameters::LogicalData b) | |
133 | - { | |
134 | - Type r; | |
135 | - r << NotANumber(); | |
136 | - if (isNAN(a) || isNAN(b)) { | |
137 | - return r; | |
138 | - } | |
139 | - r = a * (Type)b; | |
140 | - return r; | |
141 | - } | |
142 | - | |
143 | - template <typename Type> | |
144 | - Type operator *(AMDA::Parameters::LogicalData a, Type b) | |
145 | - { | |
146 | - return b * a; | |
147 | - } | |
148 | - | |
149 | - /** | |
150 | - * @brief Operator / between two scalars, one is LogicalData | |
151 | - */ | |
152 | - template <typename Type> | |
153 | - Type operator /(Type a, AMDA::Parameters::LogicalData b) | |
154 | - { | |
155 | - Type r; | |
156 | - r << NotANumber(); | |
157 | - if (isNAN(a) || isNAN(b) || (b == AMDA::Parameters::LogicalData::False)) { | |
158 | - return r; | |
159 | - } | |
160 | - r = a / (Type)b; | |
161 | - return r; | |
162 | - } | |
163 | - | |
164 | - template <typename Type> | |
165 | - Type operator /(AMDA::Parameters::LogicalData a, Type b) | |
166 | - { | |
167 | - Type r; | |
168 | - r << NotANumber(); | |
169 | - if (isNAN(a) || isNAN(b) || (b == 0)) { | |
170 | - return r; | |
171 | - } | |
172 | - r = (Type)a / b; | |
173 | - return r; | |
174 | - } | |
175 | - | |
176 | - /** | |
177 | - * @brief Operator + between two scalars, one is LogicalData | |
178 | - */ | |
179 | - template <typename Type> | |
180 | - Type operator +(Type a, AMDA::Parameters::LogicalData b) | |
181 | - { | |
182 | - Type r; | |
183 | - r << NotANumber(); | |
184 | - if (isNAN(a) || isNAN(b)) { | |
185 | - return r; | |
186 | - } | |
187 | - r = a + (Type)b; | |
188 | - return r; | |
189 | - } | |
31 | +template<typename Type1, typename Type2> | |
32 | +inline AMDA::Parameters::LogicalData And(Type1 a, Type2 b) { | |
33 | + AMDA::Parameters::LogicalData aa = castToLogicalData(a); | |
34 | + AMDA::Parameters::LogicalData bb = castToLogicalData(b); | |
35 | + AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::NaN; | |
190 | 36 | |
191 | - template <typename Type> | |
192 | - Type operator +(AMDA::Parameters::LogicalData a, Type b) | |
193 | - { | |
194 | - return b + a; | |
195 | - } | |
37 | + if (aa != AMDA::Parameters::LogicalData::NaN && bb != AMDA::Parameters::LogicalData::NaN) { | |
38 | + res = ((aa == AMDA::Parameters::LogicalData::True) && (bb == AMDA::Parameters::LogicalData::True)) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False; | |
39 | + } | |
196 | 40 | |
197 | - /** | |
198 | - * @brief Operator - between two scalars, one is LogicalData | |
199 | - */ | |
200 | - template <typename Type> | |
201 | - Type operator -(Type a, AMDA::Parameters::LogicalData b) | |
202 | - { | |
203 | - Type r; | |
204 | - r << NotANumber(); | |
205 | - if (isNAN(a) || isNAN(b)) { | |
206 | - return r; | |
207 | - } | |
208 | - r = a - (Type)b; | |
209 | - return r; | |
210 | - } | |
41 | + return res; | |
42 | +} | |
211 | 43 | |
212 | - template <typename Type> | |
213 | - Type operator -(AMDA::Parameters::LogicalData a, Type b) | |
214 | - { | |
215 | - Type r; | |
216 | - r << NotANumber(); | |
217 | - if (isNAN(a) || isNAN(b)) { | |
218 | - return r; | |
219 | - } | |
220 | - r = (Type)a - b; | |
221 | - return r; | |
222 | - } | |
223 | - | |
224 | - | |
225 | - /** | |
226 | - * @brief Operator addition between two vector | |
227 | - * @details | |
228 | - * r[0] = a[0] + b[0] | |
229 | - * r[1] = a[1] + b[1] | |
230 | - * r[2] = a[2] + b[2] | |
231 | - * @return r | |
232 | - */ | |
233 | - template <typename Type1, typename Type2> | |
234 | - std::vector<Type1> operator +(std::vector<Type1> a, std::vector<Type2> b) { | |
235 | - std::vector<Type1> r; | |
236 | - if(a.size() != b.size()) { | |
237 | - BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Add two vector of different size")); | |
238 | - } | |
239 | - | |
240 | - for(unsigned int i = 0; i < a.size(); ++i) { | |
241 | - r.push_back((Type1)(a[i] + b[i])); | |
242 | - } | |
243 | - return r; | |
244 | - } | |
245 | - | |
246 | - | |
247 | - /** | |
248 | - * @brief Operator subtraction between two vector | |
249 | - * @details | |
250 | - * r[0] = a[0] - b[0] | |
251 | - * r[1] = a[1] - b[1] | |
252 | - * r[2] = a[2] - b[2] | |
253 | - * @return r | |
254 | - */ | |
255 | - template <typename Type1, typename Type2> | |
256 | - std::vector<Type1> operator -(std::vector<Type1> a, std::vector<Type2> b) { | |
257 | - std::vector<Type1> r; | |
258 | - if(a.size() != b.size()) { | |
259 | - BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Subtract two vector of different size")); | |
260 | - } | |
261 | - | |
262 | - for(unsigned int i = 0; i < a.size(); ++i) { | |
263 | - r.push_back(a[i] - b[i]); | |
264 | - } | |
265 | - return r; | |
266 | - } | |
267 | - | |
268 | - | |
269 | - | |
270 | - /** | |
271 | - * @brief Operator dot product between two vector | |
272 | - * @details | |
273 | - * r = a[0]*b[0] + a[1]*b[1] + a[2]+b[2] | |
274 | - * @return the scalar r | |
275 | - */ | |
276 | - template <typename Type1, typename Type2> | |
277 | - Type1 operator *(std::vector<Type1> a, std::vector<Type2> b) { | |
278 | - Type1 r = 0; | |
279 | - if(a.size() != b.size()) { | |
280 | - BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Multiply two vector of different size")); | |
281 | - } | |
282 | - | |
283 | - for(unsigned int i = 0; i < a.size(); ++i) { | |
284 | - r += a[i]*b[i]; | |
285 | - } | |
286 | - return r; | |
287 | - } | |
288 | - | |
289 | - /** | |
290 | - * @brief Function dot between two vectors can be used for dot product | |
291 | - */ | |
292 | - template <typename Type1, typename Type2> | |
293 | - Type1 dot(std::vector<Type1> a, std::vector<Type2> b) { | |
294 | - return a*b; | |
295 | - } | |
44 | +/** | |
45 | + * @brief Operator Or (||) between LogicalData | |
46 | + */ | |
47 | +template<typename Type1, typename Type2> | |
48 | +inline AMDA::Parameters::LogicalData Or(Type1 a, Type2 b) { | |
49 | + AMDA::Parameters::LogicalData aa = castToLogicalData(a); | |
50 | + AMDA::Parameters::LogicalData bb = castToLogicalData(b); | |
51 | + AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::NaN; | |
52 | + | |
53 | + if (aa != AMDA::Parameters::LogicalData::NaN && bb != AMDA::Parameters::LogicalData::NaN) { | |
54 | + res = ((aa == AMDA::Parameters::LogicalData::True) || (bb == AMDA::Parameters::LogicalData::True)) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False; | |
55 | + } | |
56 | + | |
57 | + return res; | |
58 | +} | |
59 | + | |
60 | +/** | |
61 | + * @brief Operator greater_than (>) between LogicalData | |
62 | + */ | |
63 | +template <typename Type1, typename Type2> | |
64 | +AMDA::Parameters::LogicalData greater_than(Type1 a, Type2 b) { | |
65 | + AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::True; | |
66 | + if (std::isfinite(a) && std::isfinite(b)) { | |
67 | + res = (a > b) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False; | |
68 | + } else { | |
69 | + res = AMDA::Parameters::LogicalData::NaN; | |
70 | + } | |
71 | + return res; | |
72 | +} | |
73 | + | |
74 | +/** | |
75 | + * @brief Operator greater_than (>) between table of LogicalData | |
76 | + */ | |
77 | +template<typename Type1, typename Type2> | |
78 | +std::vector<AMDA::Parameters::LogicalData> greater_than(std::vector<Type1> a, | |
79 | + std::vector<Type2> b) { | |
80 | + std::vector<AMDA::Parameters::LogicalData> r; | |
81 | + if (a.size() != b.size()) { | |
82 | + BOOST_THROW_EXCEPTION( | |
83 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Logical comparison between two vector of different size")); | |
84 | + } | |
85 | + | |
86 | + for (unsigned int i = 0; i < a.size(); ++i) { | |
87 | + r.push_back(greater_than(a[i], b[i])); | |
88 | + } | |
89 | + return r; | |
90 | +} | |
91 | + | |
92 | +/** | |
93 | + * @brief Operator lower_than (<) between table of LogicalData | |
94 | + */ | |
95 | +template <typename Type1, typename Type2> | |
96 | +AMDA::Parameters::LogicalData lower_than(Type1 a, Type2 b) { | |
97 | + AMDA::Parameters::LogicalData res = AMDA::Parameters::LogicalData::True; | |
98 | + if (std::isfinite(a) && std::isfinite(b)) { | |
99 | + res = (a < b) ? AMDA::Parameters::LogicalData::True : AMDA::Parameters::LogicalData::False; | |
100 | + } else { | |
101 | + res = AMDA::Parameters::LogicalData::NaN; | |
102 | + } | |
103 | + return res; | |
104 | +} | |
105 | + | |
106 | +/** | |
107 | + * @brief Operator lower_than (<) between table of LogicalData | |
108 | + */ | |
109 | +template<typename Type1, typename Type2> | |
110 | +std::vector<AMDA::Parameters::LogicalData> lower_than(std::vector<Type1> a, | |
111 | + std::vector<Type2> b) { | |
112 | + std::vector<AMDA::Parameters::LogicalData> r; | |
113 | + if (a.size() != b.size()) { | |
114 | + BOOST_THROW_EXCEPTION( | |
115 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Logical comparison between two vector of different size")); | |
116 | + } | |
117 | + | |
118 | + for (unsigned int i = 0; i < a.size(); ++i) { | |
119 | + r.push_back(lower_than(a[i], b[i])); | |
120 | + } | |
121 | + return r; | |
122 | +} | |
123 | + | |
124 | +/** | |
125 | + * @brief Operator * between two scalars, one is LogicalData | |
126 | + */ | |
127 | +template <typename Type> | |
128 | +Type operator*(Type a, AMDA::Parameters::LogicalData b) { | |
129 | + Type r; | |
130 | + r << NotANumber(); | |
131 | + if (isNAN(a) || isNAN(b)) { | |
132 | + return r; | |
133 | + } | |
134 | + r = a * (Type) b; | |
135 | + return r; | |
136 | +} | |
137 | + | |
138 | +template <typename Type> | |
139 | +Type operator*(AMDA::Parameters::LogicalData a, Type b) { | |
140 | + return b * a; | |
141 | +} | |
142 | + | |
143 | +/** | |
144 | + * @brief Operator / between two scalars, one is LogicalData | |
145 | + */ | |
146 | +template <typename Type> | |
147 | +Type operator/(Type a, AMDA::Parameters::LogicalData b) { | |
148 | + Type r; | |
149 | + r << NotANumber(); | |
150 | + if (isNAN(a) || isNAN(b) || (b == AMDA::Parameters::LogicalData::False)) { | |
151 | + return r; | |
152 | + } | |
153 | + r = a / (Type) b; | |
154 | + return r; | |
155 | +} | |
156 | + | |
157 | +template <typename Type> | |
158 | +Type operator/(AMDA::Parameters::LogicalData a, Type b) { | |
159 | + Type r; | |
160 | + r << NotANumber(); | |
161 | + if (isNAN(a) || isNAN(b) || (b == 0)) { | |
162 | + return r; | |
163 | + } | |
164 | + r = (Type) a / b; | |
165 | + return r; | |
166 | +} | |
167 | + | |
168 | +/** | |
169 | + * @brief Operator + between two scalars, one is LogicalData | |
170 | + */ | |
171 | +template <typename Type> | |
172 | +Type operator+(Type a, AMDA::Parameters::LogicalData b) { | |
173 | + Type r; | |
174 | + r << NotANumber(); | |
175 | + if (isNAN(a) || isNAN(b)) { | |
176 | + return r; | |
177 | + } | |
178 | + r = a + (Type) b; | |
179 | + return r; | |
180 | +} | |
181 | + | |
182 | +template <typename Type> | |
183 | +Type operator+(AMDA::Parameters::LogicalData a, Type b) { | |
184 | + return b + a; | |
185 | +} | |
186 | + | |
187 | +/** | |
188 | + * @brief Operator - between two scalars, one is LogicalData | |
189 | + */ | |
190 | +template <typename Type> | |
191 | +Type operator-(Type a, AMDA::Parameters::LogicalData b) { | |
192 | + Type r; | |
193 | + r << NotANumber(); | |
194 | + if (isNAN(a) || isNAN(b)) { | |
195 | + return r; | |
196 | + } | |
197 | + r = a - (Type) b; | |
198 | + return r; | |
199 | +} | |
200 | + | |
201 | +template <typename Type> | |
202 | +Type operator-(AMDA::Parameters::LogicalData a, Type b) { | |
203 | + Type r; | |
204 | + r << NotANumber(); | |
205 | + if (isNAN(a) || isNAN(b)) { | |
206 | + return r; | |
207 | + } | |
208 | + r = (Type) a - b; | |
209 | + return r; | |
210 | +} | |
211 | + | |
212 | +/** | |
213 | + * @brief Operator addition between two vector | |
214 | + * @details | |
215 | + * r[0] = a[0] + b[0] | |
216 | + * r[1] = a[1] + b[1] | |
217 | + * r[2] = a[2] + b[2] | |
218 | + * @return r | |
219 | + */ | |
220 | +template <typename Type1, typename Type2> | |
221 | +std::vector<Type1> operator+(std::vector<Type1> a, std::vector<Type2> b) { | |
222 | + std::vector<Type1> r; | |
223 | + if (a.size() != b.size()) { | |
224 | + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Add two vector of different size")); | |
225 | + } | |
226 | + | |
227 | + for (unsigned int i = 0; i < a.size(); ++i) { | |
228 | + r.push_back((Type1) (a[i] + b[i])); | |
229 | + } | |
230 | + return r; | |
231 | +} | |
232 | + | |
233 | +/** | |
234 | + * @brief Operator subtraction between two vector | |
235 | + * @details | |
236 | + * r[0] = a[0] - b[0] | |
237 | + * r[1] = a[1] - b[1] | |
238 | + * r[2] = a[2] - b[2] | |
239 | + * @return r | |
240 | + */ | |
241 | +template <typename Type1, typename Type2> | |
242 | +std::vector<Type1> operator-(std::vector<Type1> a, std::vector<Type2> b) { | |
243 | + std::vector<Type1> r; | |
244 | + if (a.size() != b.size()) { | |
245 | + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Subtract two vector of different size")); | |
246 | + } | |
247 | + | |
248 | + for (unsigned int i = 0; i < a.size(); ++i) { | |
249 | + r.push_back(a[i] - b[i]); | |
250 | + } | |
251 | + return r; | |
252 | +} | |
296 | 253 | |
297 | - /** | |
298 | - * @brief Operator cross product between two vector | |
299 | - * @details | |
300 | - * r[0] = a[1]*b[2] - a[2]*b[1] | |
301 | - * r[1] = a[2]*b[0] - a[0]*b[2] | |
302 | - * r[2] = a[0]*b[1] - a[1]*b[0] | |
303 | - * @return r | |
304 | - */ | |
305 | - template <typename Type1, typename Type2> | |
306 | - std::vector<Type1> operator ^(std::vector<Type1> a, std::vector<Type2> b) { | |
307 | - std::vector<Type1> r; | |
308 | - if(a.size() != b.size() || b.size() != 3) { | |
309 | - BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Vector product on two vector of different size")); | |
310 | - } | |
311 | - | |
312 | - r.push_back(a[1]*b[2] - a[2]*b[1]); | |
313 | - r.push_back(a[2]*b[0] - a[0]*b[2]); | |
314 | - r.push_back(a[0]*b[1] - a[1]*b[0]); | |
315 | - | |
316 | - return r; | |
317 | - } | |
318 | - | |
319 | - /** | |
320 | - * @brief Function cross between two vectors can be used for cross product | |
321 | - */ | |
322 | - template <typename Type1, typename Type2> | |
323 | - std::vector<Type1> cross(std::vector<Type1> a, std::vector<Type2> b) { | |
324 | - return a^b; | |
325 | - } | |
326 | - | |
327 | - /** | |
328 | - * @brief div each coordinate one to one | |
329 | - * @details | |
330 | - * r[0] = a[0] / b[0] | |
331 | - * r[1] = a[1] / b[1] | |
332 | - * r[2] = a[2] / b[2] | |
333 | - */ | |
334 | - template <typename Type1, typename Type2> | |
335 | - std::vector<Type1> div(std::vector<Type1> a, std::vector<Type2> b) { | |
336 | - std::vector<Type1> r; | |
337 | - if(a.size() != b.size()) { | |
338 | - BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Vector div on two vector of different size")); | |
339 | - | |
340 | - } | |
341 | - | |
342 | - for(unsigned int i = 0; i < a.size(); ++i) { | |
343 | - r.push_back( a[i]/b[i]); | |
344 | - } | |
345 | - | |
346 | - return r; | |
347 | - } | |
348 | - | |
349 | - // | |
350 | - //Idea but more complex: template <typename Type1, typename Type2> | |
351 | - //auto operator ^(std::vector<Type1> a, std::vector<Type2> b) -> std::vector<decltype(Type1()*Type2())> { | |
352 | - // std::vector<decltype(Type1()*Type2())> r; | |
254 | +/** | |
255 | + * @brief Operator dot product between two vector | |
256 | + * @details | |
257 | + * r = a[0]*b[0] + a[1]*b[1] + a[2]+b[2] | |
258 | + * @return the scalar r | |
259 | + */ | |
260 | +template <typename Type1, typename Type2> | |
261 | +Type1 operator*(std::vector<Type1> a, std::vector<Type2> b) { | |
262 | + Type1 r = 0; | |
263 | + if (a.size() != b.size()) { | |
264 | + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Multiply two vector of different size")); | |
265 | + } | |
266 | + | |
267 | + for (unsigned int i = 0; i < a.size(); ++i) { | |
268 | + r += a[i] * b[i]; | |
269 | + } | |
270 | + return r; | |
271 | +} | |
272 | + | |
273 | +/** | |
274 | + * @brief Function dot between two vectors can be used for dot product | |
275 | + */ | |
276 | +template <typename Type1, typename Type2> | |
277 | +Type1 dot(std::vector<Type1> a, std::vector<Type2> b) { | |
278 | + return a*b; | |
279 | +} | |
280 | + | |
281 | +template <typename Type> | |
282 | +Type magnitude(std::vector<Type> a) { | |
283 | + Type mag = 0; | |
284 | + for (unsigned int i = 0; i < a.size(); ++i) | |
285 | + mag += a[i]*a[i]; | |
286 | + return std::sqrt(mag); | |
287 | +} | |
288 | + | |
289 | +template <typename Type1, typename Type2> | |
290 | +Type1 angle(std::vector<Type1> a, std::vector<Type2> b) { | |
291 | + if(magnitude(a) ==0 || magnitude(b) == 0){ | |
292 | + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("One of the two vectors is NULL")); | |
293 | + } | |
294 | + return std::acos(dot(a,b)/magnitude(a)/magnitude(b)); | |
295 | +} | |
296 | + | |
297 | +/** | |
298 | + * @brief Operator cross product between two vector | |
299 | + * @details | |
300 | + * r[0] = a[1]*b[2] - a[2]*b[1] | |
301 | + * r[1] = a[2]*b[0] - a[0]*b[2] | |
302 | + * r[2] = a[0]*b[1] - a[1]*b[0] | |
303 | + * @return r | |
304 | + */ | |
305 | +template <typename Type1, typename Type2> | |
306 | +std::vector<Type1> operator ^(std::vector<Type1> a, std::vector<Type2> b) { | |
307 | + std::vector<Type1> r; | |
308 | + if (a.size() != b.size() || b.size() != 3) { | |
309 | + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Vector product on two vector of different size")); | |
310 | + } | |
311 | + | |
312 | + r.push_back(a[1] * b[2] - a[2] * b[1]); | |
313 | + r.push_back(a[2] * b[0] - a[0] * b[2]); | |
314 | + r.push_back(a[0] * b[1] - a[1] * b[0]); | |
315 | + | |
316 | + return r; | |
317 | +} | |
318 | + | |
319 | +/** | |
320 | + * @brief Function cross between two vectors can be used for cross product | |
321 | + */ | |
322 | +template <typename Type1, typename Type2> | |
323 | +std::vector<Type1> cross(std::vector<Type1> a, std::vector<Type2> b) { | |
324 | + return a^b; | |
325 | +} | |
326 | + | |
327 | +/** | |
328 | + * @brief div each coordinate one to one | |
329 | + * @details | |
330 | + * r[0] = a[0] / b[0] | |
331 | + * r[1] = a[1] / b[1] | |
332 | + * r[2] = a[2] / b[2] | |
333 | + */ | |
334 | +template <typename Type1, typename Type2> | |
335 | +std::vector<Type1> div(std::vector<Type1> a, std::vector<Type2> b) { | |
336 | + std::vector<Type1> r; | |
337 | + if (a.size() != b.size()) { | |
338 | + BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Vector div on two vector of different size")); | |
339 | + | |
340 | + } | |
341 | + | |
342 | + for (unsigned int i = 0; i < a.size(); ++i) { | |
343 | + r.push_back(a[i] / b[i]); | |
344 | + } | |
345 | + | |
346 | + return r; | |
347 | +} | |
348 | + | |
349 | +// | |
350 | +//Idea but more complex: template <typename Type1, typename Type2> | |
351 | +//auto operator ^(std::vector<Type1> a, std::vector<Type2> b) -> std::vector<decltype(Type1()*Type2())> { | |
352 | +// std::vector<decltype(Type1()*Type2())> r; | |
353 | 353 | |
354 | 354 | |
355 | 355 | // Idea but more complex: template <typename Type1, typename Type2> |
... | ... | @@ -376,934 +376,859 @@ |
376 | 376 | // return pow(a, b._i); |
377 | 377 | // } |
378 | 378 | |
379 | - // vector with scalar operation | |
380 | - | |
381 | - /** | |
382 | - * @brief Operator division between a vector and a scalar | |
383 | - * @details all member of vector are divided by the scalar | |
384 | - */ | |
385 | - template <typename Type1, typename Type2> | |
386 | - std::vector<Type1> operator /(std::vector<Type1> a, Type2 b) { | |
387 | - std::vector<Type1> r; | |
388 | - for(typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
389 | - r.push_back((Type1)(*it / b)); | |
390 | - } | |
391 | - return r; | |
392 | - } | |
393 | - | |
394 | - /** | |
395 | - * @brief Operator division between a scalar and a vector | |
396 | - * @details apply the division on each vector component | |
397 | - */ | |
398 | - template <typename Type1, typename Type2> | |
399 | - std::vector<Type2> operator /(Type1 a, std::vector<Type2> b) { | |
400 | - std::vector<Type2> r; | |
401 | - for(typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
402 | - r.push_back((Type2)(a / *it)); | |
403 | - } | |
404 | - return r; | |
405 | - } | |
406 | - | |
407 | - | |
408 | - /** | |
409 | - * @brief Operator addition between a vector and a scalar | |
410 | - * @details all member of vector are added with the scalar | |
411 | - */ | |
412 | - template <typename Type1, typename Type2> | |
413 | - std::vector<Type1> operator +(std::vector<Type1> a, Type2 b) { | |
414 | - std::vector<Type1> r; | |
415 | - for(typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
416 | - r.push_back((Type1)(*it + b)); | |
417 | - } | |
418 | - return r; | |
419 | - } | |
420 | - | |
421 | - /** | |
422 | - * @brief Operator addition between a scalar and a vector | |
423 | - * @details all member of vector are added with the scalar | |
424 | - */ | |
425 | - template <typename Type1, typename Type2> | |
426 | - std::vector<Type2> operator +( Type1 a, std::vector<Type2> b) { | |
427 | - std::vector<Type2> r; | |
428 | - for(typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
429 | - r.push_back((Type2)(a + *it)); | |
430 | - } | |
431 | - return r; | |
379 | +// vector with scalar operation | |
380 | + | |
381 | +/** | |
382 | + * @brief Operator division between a vector and a scalar | |
383 | + * @details all member of vector are divided by the scalar | |
384 | + */ | |
385 | +template <typename Type1, typename Type2> | |
386 | +std::vector<Type1> operator/(std::vector<Type1> a, Type2 b) { | |
387 | + std::vector<Type1> r; | |
388 | + for (typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
389 | + r.push_back((Type1) (*it / b)); | |
390 | + } | |
391 | + return r; | |
392 | +} | |
393 | + | |
394 | +/** | |
395 | + * @brief Operator division between a scalar and a vector | |
396 | + * @details apply the division on each vector component | |
397 | + */ | |
398 | +template <typename Type1, typename Type2> | |
399 | +std::vector<Type2> operator/(Type1 a, std::vector<Type2> b) { | |
400 | + std::vector<Type2> r; | |
401 | + for (typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
402 | + r.push_back((Type2) (a / *it)); | |
403 | + } | |
404 | + return r; | |
405 | +} | |
406 | + | |
407 | +/** | |
408 | + * @brief Operator addition between a vector and a scalar | |
409 | + * @details all member of vector are added with the scalar | |
410 | + */ | |
411 | +template <typename Type1, typename Type2> | |
412 | +std::vector<Type1> operator+(std::vector<Type1> a, Type2 b) { | |
413 | + std::vector<Type1> r; | |
414 | + for (typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
415 | + r.push_back((Type1) (*it + b)); | |
416 | + } | |
417 | + return r; | |
418 | +} | |
419 | + | |
420 | +/** | |
421 | + * @brief Operator addition between a scalar and a vector | |
422 | + * @details all member of vector are added with the scalar | |
423 | + */ | |
424 | +template <typename Type1, typename Type2> | |
425 | +std::vector<Type2> operator+(Type1 a, std::vector<Type2> b) { | |
426 | + std::vector<Type2> r; | |
427 | + for (typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
428 | + r.push_back((Type2) (a + *it)); | |
429 | + } | |
430 | + return r; | |
431 | +} | |
432 | + | |
433 | +/** | |
434 | + * @brief Operator subtraction between a vector and a scalar | |
435 | + * @details scalar is substracted to all vector components | |
436 | + */ | |
437 | +template <typename Type1, typename Type2> | |
438 | +std::vector<Type1> operator-(std::vector<Type1> a, Type2 b) { | |
439 | + std::vector<Type1> r; | |
440 | + for (typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
441 | + r.push_back((Type1) (*it - b)); | |
442 | + } | |
443 | + return r; | |
444 | +} | |
445 | + | |
446 | +/** | |
447 | + * @brief Operator subtraction between a scalar and a vector | |
448 | + * @details all member of vector are subtracted with the scalar | |
449 | + */ | |
450 | +template <typename Type1, typename Type2> | |
451 | +std::vector<Type2> operator-(Type1 a, std::vector<Type2> b) { | |
452 | + std::vector<Type2> r; | |
453 | + for (typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
454 | + r.push_back((Type2) (a - *it)); | |
455 | + } | |
456 | + return r; | |
457 | +} | |
458 | + | |
459 | +/** | |
460 | + * @brief Operator product between a vector and a scalar | |
461 | + * @details product applied in all member of vector | |
462 | + */ | |
463 | +template <typename Type1, typename Type2> | |
464 | +std::vector<Type1> operator*(std::vector<Type1> a, Type2 b) { | |
465 | + std::vector<Type1> r; | |
466 | + for (typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
467 | + r.push_back((Type1) ((*it) * b)); | |
468 | + } | |
469 | + return r; | |
470 | +} | |
471 | + | |
472 | +/** | |
473 | + * @brief Operator product between a scalar and a vector | |
474 | + * @details all member of vector are added by the scalar | |
475 | + */ | |
476 | +template <typename Type1, typename Type2> | |
477 | +std::vector<Type2> operator*(Type1 a, std::vector<Type2> b) { | |
478 | + std::vector<Type2> r; | |
479 | + for (typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
480 | + r.push_back((Type2) (a * (*it))); | |
481 | + } | |
482 | + return r; | |
483 | +} | |
484 | + | |
485 | +/** | |
486 | + * @return false if val is NaN or inf or -inf | |
487 | + */ | |
488 | +template <typename Type> | |
489 | +inline bool isFinite(Type val) { | |
490 | + return std::isfinite(val); | |
491 | +} | |
492 | + | |
493 | +inline bool isFinite(AMDA::Parameters::LogicalData val) { | |
494 | + return !isNAN(val); | |
495 | +} | |
496 | + | |
497 | +/** | |
498 | + * @return false if elem of val is NaN or inf or -inf | |
499 | + */ | |
500 | +template <typename Type> | |
501 | +inline bool isFinite(std::vector<Type> val) { | |
502 | + bool ret = false; | |
503 | + auto it = val.begin(); | |
504 | + while (it != val.end() && !ret) { | |
505 | + ret &= std::isfinite(*it); | |
506 | + ++it; | |
507 | + } | |
508 | + return ret; | |
509 | +} | |
510 | + | |
511 | +/** | |
512 | + * @return false if elem of val is NaN or inf or -inf | |
513 | + */ | |
514 | +template <typename Type> | |
515 | +inline bool isFinite(const AMDA::Parameters::Tab2DData<Type>& val) { | |
516 | + bool ret = false; | |
517 | + for (int i = 0; i < val.getDim1Size(); ++i) | |
518 | + for (int j = 0; j < val.getDim2Size(); ++j) | |
519 | + ret &= std::isfinite(val[i][j]); | |
520 | + return ret; | |
521 | +} | |
522 | + | |
523 | +/** | |
524 | + * @return the average of std::list | |
525 | + */ | |
526 | +template <typename Type> | |
527 | +inline Type average(std::list<Type> tab, int /*dim1*/, int /*dim2*/) { | |
528 | + Type mean; | |
529 | + if (tab.empty()) { | |
530 | + mean << NotANumber(); | |
531 | + } else { | |
532 | + mean << ElemNull(); | |
533 | + auto it = tab.begin(); | |
534 | + if (it != tab.end()) { | |
535 | + unsigned int nbNan = 0; | |
536 | + Type sum; | |
537 | + sum << NotANumber(); | |
538 | + for (; it != tab.end(); ++it) { | |
539 | + if (isFinite(*it) && !isNAN(*it)) { | |
540 | + if (isNAN(sum)) | |
541 | + sum = *it; | |
542 | + else | |
543 | + sum = sum + *it; | |
544 | + } else { | |
545 | + ++nbNan; | |
546 | + } | |
547 | + } | |
548 | + if ((tab.size() - nbNan == 0) || isNAN(sum)) { | |
549 | + mean << NotANumber(); | |
550 | + } else { | |
551 | + mean = sum / (int) (tab.size() - nbNan); | |
552 | + } | |
553 | + } else { | |
554 | + mean << NotANumber(); | |
555 | + } | |
556 | + } | |
557 | + return mean; | |
558 | +} | |
559 | + | |
560 | +inline AMDA::Parameters::LogicalData average(std::list<AMDA::Parameters::LogicalData> /*tab*/, int /*dim1*/, int /*dim2*/) { | |
561 | + AMDA::Parameters::LogicalData mean; | |
562 | + mean << NotANumber(); | |
563 | + return mean; | |
564 | +} | |
565 | + | |
566 | +template <typename Type> | |
567 | +inline AMDA::Parameters::Tab2DData<Type> average(std::list<AMDA::Parameters::Tab2DData<Type> > tab, int dim1, int dim2) { | |
568 | + AMDA::Parameters::Tab2DData<Type> mean(dim1, dim2); | |
569 | + AMDA::Parameters::Tab2DData<unsigned int > nbNan(dim1, dim2); | |
570 | + AMDA::Parameters::Tab2DData<Type> sum(dim1, dim2); | |
571 | + if (tab.empty()) { | |
572 | + mean << NotANumber(); | |
573 | + return mean; | |
574 | + } | |
575 | + for (int index1 = 0; index1 < dim1; ++index1) { | |
576 | + for (int index2 = 0; index2 < dim2; ++index2) { | |
577 | + nbNan[index1][index2] = 0; | |
578 | + } | |
579 | + } | |
580 | + sum << NotANumber(); | |
581 | + for (auto it = tab.begin(); it != tab.end(); ++it) { | |
582 | + for (int index1 = 0; index1 < dim1; ++index1) { | |
583 | + for (int index2 = 0; index2 < dim2; ++index2) { | |
584 | + Type val = (*it)[index1][index2]; | |
585 | + if (std::isfinite(val) && !isNAN(val)) { | |
586 | + if (isNAN(sum[index1][index2])) | |
587 | + sum[index1][index2] = val; | |
588 | + else | |
589 | + sum[index1][index2] += val; | |
590 | + } else { | |
591 | + ++(nbNan[index1][index2]); | |
592 | + } | |
593 | + } | |
594 | + } | |
595 | + } | |
596 | + for (int index1 = 0; index1 < dim1; ++index1) { | |
597 | + for (int index2 = 0; index2 < dim2; ++index2) { | |
598 | + if (tab.size() - nbNan[index1][index2] == 0) { | |
599 | + mean[index1][index2] << NotANumber(); | |
600 | + } else { | |
601 | + mean[index1][index2] = sum[index1][index2] / (int) (tab.size() - nbNan[index1][index2]); | |
602 | + } | |
432 | 603 | } |
604 | + } | |
605 | + | |
606 | + return mean; | |
607 | +} | |
433 | 608 | |
434 | - /** | |
435 | - * @brief Operator subtraction between a vector and a scalar | |
436 | - * @details scalar is substracted to all vector components | |
437 | - */ | |
438 | - template <typename Type1, typename Type2> | |
439 | - std::vector<Type1> operator -(std::vector<Type1> a, Type2 b) { | |
440 | - std::vector<Type1> r; | |
441 | - for(typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
442 | - r.push_back((Type1)(*it-b)); | |
443 | - } | |
444 | - return r; | |
445 | - } | |
446 | - | |
447 | - /** | |
448 | - * @brief Operator subtraction between a scalar and a vector | |
449 | - * @details all member of vector are subtracted with the scalar | |
450 | - */ | |
451 | - template <typename Type1, typename Type2> | |
452 | - std::vector<Type2> operator -(Type1 a, std::vector<Type2> b) { | |
453 | - std::vector<Type2> r; | |
454 | - for(typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
455 | - r.push_back((Type2)(a-*it)); | |
456 | - } | |
457 | - return r; | |
458 | - } | |
459 | - | |
460 | - /** | |
461 | - * @brief Operator product between a vector and a scalar | |
462 | - * @details product applied in all member of vector | |
463 | - */ | |
464 | - template <typename Type1, typename Type2> | |
465 | - std::vector<Type1> operator *(std::vector<Type1> a, Type2 b) { | |
466 | - std::vector<Type1> r; | |
467 | - for(typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
468 | - r.push_back((Type1)((*it) * b)); | |
469 | - } | |
470 | - return r; | |
471 | - } | |
472 | - | |
473 | - /** | |
474 | - * @brief Operator product between a scalar and a vector | |
475 | - * @details all member of vector are added by the scalar | |
476 | - */ | |
477 | - template <typename Type1, typename Type2> | |
478 | - std::vector<Type2> operator *( Type1 a, std::vector<Type2> b) { | |
479 | - std::vector<Type2> r; | |
480 | - for(typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
481 | - r.push_back((Type2)(a * (*it))); | |
482 | - } | |
483 | - return r; | |
484 | - } | |
485 | - | |
486 | - | |
487 | - | |
488 | - /** | |
489 | - * @return false if val is NaN or inf or -inf | |
490 | - */ | |
491 | - template <typename Type> | |
492 | - inline bool isFinite(Type val) { | |
493 | - return std::isfinite(val); | |
494 | - } | |
495 | - | |
496 | - inline bool isFinite(AMDA::Parameters::LogicalData val) { | |
497 | - return !isNAN(val); | |
609 | +inline AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData> average(std::list<AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData>> /*tab*/, int dim1, int dim2) { | |
610 | + AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData> mean(dim1, dim2); | |
611 | + mean << NotANumber(); | |
612 | + return mean; | |
613 | +} | |
614 | + | |
615 | +/** | |
616 | + * @return the average of std::list | |
617 | + */ | |
618 | +template <typename Type> | |
619 | +inline std::vector<Type> average(std::list<std::vector<Type> > tab, int dim1, int /*dim2*/) { | |
620 | + std::vector<Type> mean; | |
621 | + mean.resize(dim1); | |
622 | + std::vector<unsigned int >nbNan; | |
623 | + nbNan.resize(dim1); | |
624 | + std::vector<Type> sum; | |
625 | + sum.resize(dim1); | |
626 | + if (tab.empty()) { | |
627 | + mean << NotANumber(); | |
628 | + return mean; | |
629 | + } | |
630 | + for (unsigned int index = 0; index < tab.begin()->size(); ++index) { | |
631 | + nbNan[index] = 0; | |
632 | + } | |
633 | + sum << NotANumber(); | |
634 | + for (auto it = tab.begin(); it != tab.end(); ++it) { | |
635 | + for (unsigned int index = 0; index < it->size(); ++index) { | |
636 | + Type val = it->at(index); | |
637 | + if (std::isfinite(val) && !isNAN(val)) { | |
638 | + if (isNAN(sum[index])) | |
639 | + sum[index] = val; | |
640 | + else | |
641 | + sum[index] += val; | |
642 | + } else { | |
643 | + ++(nbNan[index]); | |
644 | + } | |
645 | + } | |
646 | + } | |
647 | + for (unsigned int index = 0; index < tab.begin()->size(); ++index) { | |
648 | + if (tab.size() - nbNan[index] == 0) { | |
649 | + mean[index] << NotANumber(); | |
650 | + } else { | |
651 | + mean[index] = sum[index] / (int) (tab.size() - nbNan[index]); | |
498 | 652 | } |
653 | + } | |
654 | + | |
499 | 655 | |
656 | + return mean; | |
657 | +} | |
500 | 658 | |
501 | - /** | |
502 | - * @return false if elem of val is NaN or inf or -inf | |
503 | - */ | |
504 | - template <typename Type> | |
505 | - inline bool isFinite(std::vector<Type> val) { | |
506 | - bool ret =false; | |
507 | - auto it = val.begin(); | |
508 | - while(it != val.end() && !ret) { | |
509 | - ret &= std::isfinite(*it); | |
510 | - ++it; | |
511 | - } | |
512 | - return ret; | |
513 | - } | |
514 | - | |
515 | - /** | |
516 | - * @return false if elem of val is NaN or inf or -inf | |
517 | - */ | |
518 | - template <typename Type> | |
519 | - inline bool isFinite(const AMDA::Parameters::Tab2DData<Type>& val) { | |
520 | - bool ret =false; | |
521 | - for (int i = 0; i < val.getDim1Size(); ++i) | |
522 | - for (int j = 0; j < val.getDim2Size(); ++j) | |
523 | - ret &= std::isfinite(val[i][j]); | |
524 | - return ret; | |
525 | - } | |
526 | - | |
527 | - /** | |
528 | - * @return the average of std::list | |
529 | - */ | |
530 | - template <typename Type> | |
531 | - inline Type average(std::list<Type> tab, int /*dim1*/, int /*dim2*/) { | |
532 | - Type mean; | |
533 | - if(tab.empty()) { | |
534 | - mean << NotANumber(); | |
535 | - } | |
536 | - else { | |
537 | - mean << ElemNull(); | |
538 | - auto it = tab.begin(); | |
539 | - if (it != tab.end()) { | |
540 | - unsigned int nbNan = 0; | |
541 | - Type sum; | |
542 | - sum << NotANumber(); | |
543 | - for (; it != tab.end(); ++it) { | |
544 | - if(isFinite(*it) && !isNAN(*it)) { | |
545 | - if (isNAN(sum)) | |
546 | - sum = *it; | |
547 | - else | |
548 | - sum = sum + *it; | |
549 | - } | |
550 | - else { | |
551 | - ++nbNan; | |
552 | - } | |
553 | - } | |
554 | - if ((tab.size() - nbNan == 0) || isNAN(sum)) { | |
555 | - mean << NotANumber(); | |
556 | - } | |
557 | - else { | |
558 | - mean = sum / (int)(tab.size() - nbNan); | |
559 | - } | |
560 | - } | |
561 | - else { | |
562 | - mean << NotANumber(); | |
563 | - } | |
564 | - } | |
565 | - return mean; | |
566 | - } | |
567 | - | |
568 | - inline AMDA::Parameters::LogicalData average(std::list<AMDA::Parameters::LogicalData> /*tab*/, int /*dim1*/, int /*dim2*/) { | |
569 | - AMDA::Parameters::LogicalData mean; | |
570 | - mean << NotANumber(); | |
571 | - return mean; | |
572 | - } | |
573 | - | |
574 | - template <typename Type> | |
575 | - inline AMDA::Parameters::Tab2DData<Type> average(std::list<AMDA::Parameters::Tab2DData<Type> > tab, int dim1, int dim2) { | |
576 | - AMDA::Parameters::Tab2DData<Type> mean(dim1,dim2); | |
577 | - AMDA::Parameters::Tab2DData<unsigned int > nbNan(dim1,dim2); | |
578 | - AMDA::Parameters::Tab2DData<Type> sum(dim1,dim2); | |
579 | - if(tab.empty()) { | |
580 | - mean << NotANumber(); | |
581 | - return mean; | |
582 | - } | |
583 | - for (int index1 = 0; index1 < dim1; ++index1) { | |
584 | - for (int index2 = 0; index2 < dim2; ++index2) { | |
585 | - nbNan[index1][index2] = 0; | |
586 | - } | |
587 | - } | |
588 | - sum << NotANumber(); | |
589 | - for (auto it = tab.begin(); it != tab.end(); ++it) { | |
590 | - for(int index1 = 0; index1 < dim1; ++index1) { | |
591 | - for(int index2 = 0; index2 < dim2; ++index2) { | |
592 | - Type val = (*it)[index1][index2]; | |
593 | - if(std::isfinite(val) && !isNAN(val)) { | |
594 | - if (isNAN(sum[index1][index2])) | |
595 | - sum[index1][index2] = val; | |
596 | - else | |
597 | - sum[index1][index2] +=val; | |
598 | - } | |
599 | - else { | |
600 | - ++(nbNan[index1][index2]); | |
601 | - } | |
602 | - } | |
603 | - } | |
604 | - } | |
605 | - for(int index1 = 0; index1 < dim1; ++index1) { | |
606 | - for(int index2 = 0; index2 < dim2; ++index2) { | |
607 | - if (tab.size() - nbNan[index1][index2] == 0) { | |
608 | - mean[index1][index2] << NotANumber(); | |
609 | - } | |
610 | - else { | |
611 | - mean[index1][index2] = sum[index1][index2] / (int)(tab.size() - nbNan[index1][index2]); | |
612 | - } | |
613 | - } | |
614 | - } | |
615 | - | |
616 | - return mean; | |
617 | - } | |
618 | - | |
619 | - inline AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData> average(std::list<AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData>> /*tab*/, int dim1, int dim2) { | |
620 | - AMDA::Parameters::Tab2DData<AMDA::Parameters::LogicalData> mean(dim1,dim2); | |
621 | - mean << NotANumber(); | |
622 | - return mean; | |
623 | - } | |
624 | - | |
625 | - /** | |
626 | - * @return the average of std::list | |
627 | - */ | |
628 | - template <typename Type> | |
629 | - inline std::vector<Type> average(std::list<std::vector<Type> > tab, int dim1, int /*dim2*/) { | |
630 | - std::vector<Type> mean; | |
631 | - mean.resize(dim1); | |
632 | - std::vector<unsigned int >nbNan; | |
633 | - nbNan.resize(dim1); | |
634 | - std::vector<Type> sum; | |
635 | - sum.resize(dim1); | |
636 | - if(tab.empty()) { | |
637 | - mean << NotANumber(); | |
638 | - return mean; | |
639 | - } | |
640 | - for(unsigned int index = 0; index < tab.begin()->size(); ++index) { | |
641 | - nbNan[index] = 0; | |
642 | - } | |
643 | - sum << NotANumber(); | |
644 | - for (auto it = tab.begin(); it != tab.end(); ++it) { | |
645 | - for(unsigned int index = 0; index < it->size(); ++index) { | |
646 | - Type val = it->at(index); | |
647 | - if(std::isfinite(val) && !isNAN(val)) { | |
648 | - if (isNAN(sum[index])) | |
649 | - sum[index] = val; | |
650 | - else | |
651 | - sum[index] +=val; | |
652 | - } | |
653 | - else { | |
654 | - ++(nbNan[index]); | |
655 | - } | |
656 | - } | |
657 | - } | |
658 | - for(unsigned int index = 0; index < tab.begin()->size(); ++index) { | |
659 | - if (tab.size() - nbNan[index] == 0) { | |
660 | - mean[index] << NotANumber(); | |
661 | - } | |
662 | - else { | |
663 | - mean[index] = sum[index] / (int)(tab.size() - nbNan[index]); | |
664 | - } | |
665 | - } | |
666 | - | |
667 | - | |
668 | - return mean; | |
669 | - } | |
670 | - | |
671 | - inline std::vector<AMDA::Parameters::LogicalData> average(std::list<std::vector<AMDA::Parameters::LogicalData>> /*tab*/, int dim1, int /*dim2*/) { | |
672 | - std::vector<AMDA::Parameters::LogicalData> mean; | |
673 | - mean.resize(dim1); | |
674 | - mean << NotANumber(); | |
675 | - return mean; | |
676 | - } | |
659 | +inline std::vector<AMDA::Parameters::LogicalData> average(std::list<std::vector<AMDA::Parameters::LogicalData>> /*tab*/, int dim1, int /*dim2*/) { | |
660 | + std::vector<AMDA::Parameters::LogicalData> mean; | |
661 | + mean.resize(dim1); | |
662 | + mean << NotANumber(); | |
663 | + return mean; | |
664 | +} | |
677 | 665 | |
678 | 666 | /** |
679 | 667 | * |
680 | 668 | */ |
681 | - template <typename Type> | |
682 | - inline Type interpolation(const Type& leftVal, const Type& rightVal, double coef, int /*dim1*/, int /*dim2*/) { | |
683 | - Type val; | |
684 | - val << NotANumber(); | |
685 | - if (isNAN(leftVal) || isNAN(rightVal) || coef < 0. || coef > 1.) | |
686 | - return val; | |
687 | - val = leftVal + (rightVal - leftVal) * coef; | |
688 | - return val; | |
689 | - } | |
669 | +template <typename Type> | |
670 | +inline Type interpolation(const Type& leftVal, const Type& rightVal, double coef, int /*dim1*/, int /*dim2*/) { | |
671 | + Type val; | |
672 | + val << NotANumber(); | |
673 | + if (isNAN(leftVal) || isNAN(rightVal) || coef < 0. || coef > 1.) | |
674 | + return val; | |
675 | + val = leftVal + (rightVal - leftVal) * coef; | |
676 | + return val; | |
677 | +} | |
690 | 678 | |
691 | - inline AMDA::Parameters::LogicalData interpolation(const AMDA::Parameters::LogicalData& leftVal, const AMDA::Parameters::LogicalData& rightVal, double /*coef*/, int /*dim1*/, int /*dim2*/) { | |
692 | - AMDA::Parameters::LogicalData val; | |
693 | - if (leftVal == rightVal) { | |
694 | - val = leftVal; | |
695 | - } | |
696 | - else { | |
697 | - val << NotANumber(); | |
698 | - } | |
699 | - return val; | |
700 | - } | |
679 | +inline AMDA::Parameters::LogicalData interpolation(const AMDA::Parameters::LogicalData& leftVal, const AMDA::Parameters::LogicalData& rightVal, double /*coef*/, int /*dim1*/, int /*dim2*/) { | |
680 | + AMDA::Parameters::LogicalData val; | |
681 | + if (leftVal == rightVal) { | |
682 | + val = leftVal; | |
683 | + } else { | |
684 | + val << NotANumber(); | |
685 | + } | |
686 | + return val; | |
687 | +} | |
701 | 688 | |
702 | 689 | /** |
703 | 690 | * |
704 | 691 | */ |
705 | 692 | |
706 | - template <typename Type> | |
707 | - inline AMDA::Parameters::Tab2DData<Type> interpolation(const AMDA::Parameters::Tab2DData<Type>& leftVal, const AMDA::Parameters::Tab2DData<Type>& rightVal, double coef, int dim1, int dim2) { | |
708 | - AMDA::Parameters::Tab2DData<Type> val(dim1,dim2); | |
709 | - val << NotANumber(); | |
710 | - for(int index1 = 0; index1 < dim1; ++index1) { | |
711 | - for(int index2 = 0; index2 < dim2; ++index2) { | |
712 | - Type leftValComp = leftVal[index1][index2]; | |
713 | - Type rightValComp = rightVal[index1][index2]; | |
714 | - val[index1][index2] = interpolation(leftValComp, rightValComp, coef, 1, 1); | |
715 | - } | |
716 | - } | |
717 | - return val; | |
718 | - } | |
719 | - | |
720 | - template <typename Type> | |
721 | - inline std::vector<Type> interpolation(const std::vector<Type>& leftVal, const std::vector<Type>& rightVal, double coef, int dim1, int /*dim2*/) { | |
722 | - std::vector<Type> val; | |
723 | - val.resize(dim1); | |
724 | - val << NotANumber(); | |
725 | - for(int index = 0; index < dim1; ++index) { | |
726 | - Type leftValComp = leftVal[index]; | |
727 | - Type rightValComp = rightVal[index]; | |
728 | - val[index] = interpolation(leftValComp, rightValComp, coef, 1, 1); | |
729 | - } | |
730 | - return val; | |
731 | - } | |
693 | +template <typename Type> | |
694 | +inline AMDA::Parameters::Tab2DData<Type> interpolation(const AMDA::Parameters::Tab2DData<Type>& leftVal, const AMDA::Parameters::Tab2DData<Type>& rightVal, double coef, int dim1, int dim2) { | |
695 | + AMDA::Parameters::Tab2DData<Type> val(dim1, dim2); | |
696 | + val << NotANumber(); | |
697 | + for (int index1 = 0; index1 < dim1; ++index1) { | |
698 | + for (int index2 = 0; index2 < dim2; ++index2) { | |
699 | + Type leftValComp = leftVal[index1][index2]; | |
700 | + Type rightValComp = rightVal[index1][index2]; | |
701 | + val[index1][index2] = interpolation(leftValComp, rightValComp, coef, 1, 1); | |
702 | + } | |
703 | + } | |
704 | + return val; | |
705 | +} | |
706 | + | |
707 | +template <typename Type> | |
708 | +inline std::vector<Type> interpolation(const std::vector<Type>& leftVal, const std::vector<Type>& rightVal, double coef, int dim1, int /*dim2*/) { | |
709 | + std::vector<Type> val; | |
710 | + val.resize(dim1); | |
711 | + val << NotANumber(); | |
712 | + for (int index = 0; index < dim1; ++index) { | |
713 | + Type leftValComp = leftVal[index]; | |
714 | + Type rightValComp = rightVal[index]; | |
715 | + val[index] = interpolation(leftValComp, rightValComp, coef, 1, 1); | |
716 | + } | |
717 | + return val; | |
718 | +} | |
732 | 719 | |
733 | 720 | /** |
734 | 721 | * @brief Operator + between Tab2D and scalar |
735 | 722 | */ |
736 | 723 | template <typename Type1, typename Type2> |
737 | -AMDA::Parameters::Tab2DData<Type1> operator +(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) | |
738 | -{ | |
739 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
740 | - | |
741 | - if (isNAN(b)) | |
742 | - { | |
743 | - r << NotANumber(); | |
744 | - return r; | |
745 | - } | |
746 | - | |
747 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
748 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
749 | - { | |
750 | - if (!isNAN(r[i][j])) | |
751 | - r[i][j] += b; | |
752 | - } | |
753 | - return r; | |
724 | +AMDA::Parameters::Tab2DData<Type1> operator+(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) { | |
725 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
726 | + | |
727 | + if (isNAN(b)) { | |
728 | + r << NotANumber(); | |
729 | + return r; | |
730 | + } | |
731 | + | |
732 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
733 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
734 | + if (!isNAN(r[i][j])) | |
735 | + r[i][j] += b; | |
736 | + } | |
737 | + return r; | |
754 | 738 | } |
755 | 739 | |
756 | 740 | template <typename Type1, typename Type2> |
757 | -AMDA::Parameters::Tab2DData<Type2> operator +(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
758 | -{ | |
759 | - return (b+a); | |
741 | +AMDA::Parameters::Tab2DData<Type2> operator+(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
742 | + return (b + a); | |
760 | 743 | } |
761 | 744 | |
762 | 745 | /** |
763 | 746 | * @brief Operator - between Tab2D and scalar |
764 | 747 | */ |
765 | 748 | template <typename Type1, typename Type2> |
766 | -AMDA::Parameters::Tab2DData<Type1> operator -(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) | |
767 | -{ | |
768 | - return (a+(-b)); | |
749 | +AMDA::Parameters::Tab2DData<Type1> operator-(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) { | |
750 | + return (a + (-b)); | |
769 | 751 | } |
770 | 752 | |
771 | 753 | template <typename Type1, typename Type2> |
772 | -AMDA::Parameters::Tab2DData<Type2> operator -(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
773 | -{ | |
774 | - AMDA::Parameters::Tab2DData<Type2> r(b); | |
775 | - | |
776 | - if (isNAN(a)) | |
777 | - { | |
778 | - r << NotANumber(); | |
779 | - return r; | |
780 | - } | |
781 | - | |
782 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
783 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
784 | - { | |
785 | - if (!isNAN(r[i][j])) | |
786 | - r[i][j] = a - r[i][j]; | |
787 | - } | |
788 | - return r; | |
754 | +AMDA::Parameters::Tab2DData<Type2> operator-(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
755 | + AMDA::Parameters::Tab2DData<Type2> r(b); | |
756 | + | |
757 | + if (isNAN(a)) { | |
758 | + r << NotANumber(); | |
759 | + return r; | |
760 | + } | |
761 | + | |
762 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
763 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
764 | + if (!isNAN(r[i][j])) | |
765 | + r[i][j] = a - r[i][j]; | |
766 | + } | |
767 | + return r; | |
789 | 768 | } |
790 | 769 | |
791 | 770 | /** |
792 | 771 | * @brief Operator * between Tab2D and scalar |
793 | 772 | */ |
794 | 773 | template <typename Type1, typename Type2> |
795 | -AMDA::Parameters::Tab2DData<Type1> operator *(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) | |
796 | -{ | |
797 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
798 | - | |
799 | - if (isNAN(b)) | |
800 | - { | |
801 | - r << NotANumber(); | |
802 | - return r; | |
803 | - } | |
804 | - | |
805 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
806 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
807 | - { | |
808 | - if (!isNAN(r[i][j])) | |
809 | - r[i][j] *= b; | |
810 | - } | |
811 | - return r; | |
774 | +AMDA::Parameters::Tab2DData<Type1> operator*(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) { | |
775 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
776 | + | |
777 | + if (isNAN(b)) { | |
778 | + r << NotANumber(); | |
779 | + return r; | |
780 | + } | |
781 | + | |
782 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
783 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
784 | + if (!isNAN(r[i][j])) | |
785 | + r[i][j] *= b; | |
786 | + } | |
787 | + return r; | |
812 | 788 | } |
813 | 789 | |
814 | 790 | template <typename Type1, typename Type2> |
815 | -AMDA::Parameters::Tab2DData<Type2> operator *(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
816 | -{ | |
817 | - return (b*a); | |
791 | +AMDA::Parameters::Tab2DData<Type2> operator*(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
792 | + return (b * a); | |
818 | 793 | } |
819 | 794 | |
820 | 795 | /** |
821 | 796 | * @brief Operator / between Tab2D and scalar |
822 | 797 | */ |
823 | 798 | template <typename Type1, typename Type2> |
824 | -AMDA::Parameters::Tab2DData<Type1> operator /(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) | |
825 | -{ | |
826 | - if (b==0) | |
827 | - { | |
828 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
829 | - r << NotANumber(); | |
830 | - return r; | |
831 | - } | |
832 | - return (a*(1./b)); | |
799 | +AMDA::Parameters::Tab2DData<Type1> operator/(const AMDA::Parameters::Tab2DData<Type1>& a, Type2 b) { | |
800 | + if (b == 0) { | |
801 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
802 | + r << NotANumber(); | |
803 | + return r; | |
804 | + } | |
805 | + return (a * (1. / b)); | |
833 | 806 | } |
834 | 807 | |
835 | 808 | template <typename Type1, typename Type2> |
836 | -AMDA::Parameters::Tab2DData<Type2> operator /(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
837 | -{ | |
838 | - AMDA::Parameters::Tab2DData<Type2> r(b); | |
839 | - | |
840 | - if (isNAN(a)) | |
841 | - { | |
842 | - r << NotANumber(); | |
843 | - return r; | |
844 | - } | |
845 | - | |
846 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
847 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
848 | - { | |
849 | - if (isNAN(r[i][j]) || (r[i][j] == 0)) | |
850 | - r[i][j] << NotANumber(); | |
851 | - else | |
852 | - r[i][j] = a / r[i][j]; | |
853 | - } | |
854 | - return r; | |
809 | +AMDA::Parameters::Tab2DData<Type2> operator/(Type1 a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
810 | + AMDA::Parameters::Tab2DData<Type2> r(b); | |
811 | + | |
812 | + if (isNAN(a)) { | |
813 | + r << NotANumber(); | |
814 | + return r; | |
815 | + } | |
816 | + | |
817 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
818 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
819 | + if (isNAN(r[i][j]) || (r[i][j] == 0)) | |
820 | + r[i][j] << NotANumber(); | |
821 | + else | |
822 | + r[i][j] = a / r[i][j]; | |
823 | + } | |
824 | + return r; | |
855 | 825 | } |
856 | 826 | |
857 | 827 | /* |
858 | 828 | * @brief Function add between a Tab2D and a vector |
859 | 829 | */ |
860 | 830 | template <typename Type1, typename Type2> |
861 | -AMDA::Parameters::Tab2DData<Type1> add(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) | |
862 | -{ | |
863 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
864 | - | |
865 | - switch (mode) | |
866 | - { | |
867 | - case 1 : | |
868 | - if (r.getDim1Size() != b.size()) { | |
869 | - BOOST_THROW_EXCEPTION( | |
870 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
871 | - } | |
872 | - | |
873 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
874 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
875 | - { | |
876 | - if (isNAN(r[i][j]) || isNAN(b[i])) | |
877 | - r[i][j] << NotANumber(); | |
878 | - else | |
879 | - r[i][j] += b[i]; | |
880 | - } | |
881 | - break; | |
882 | - case 2 : | |
883 | - if (r.getDim2Size() != b.size()) { | |
884 | - BOOST_THROW_EXCEPTION( | |
885 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
886 | - } | |
887 | - | |
888 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
889 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
890 | - { | |
891 | - if (isNAN(r[i][j]) || isNAN(b[j])) | |
892 | - r[i][j] << NotANumber(); | |
893 | - else | |
894 | - r[i][j] += b[j]; | |
895 | - } | |
896 | - break; | |
897 | - default: | |
898 | - BOOST_THROW_EXCEPTION( | |
899 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
900 | - } | |
901 | - return r; | |
831 | +AMDA::Parameters::Tab2DData<Type1> add(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) { | |
832 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
833 | + | |
834 | + switch (mode) { | |
835 | + case 1: | |
836 | + if (r.getDim1Size() != b.size()) { | |
837 | + BOOST_THROW_EXCEPTION( | |
838 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
839 | + } | |
840 | + | |
841 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
842 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
843 | + if (isNAN(r[i][j]) || isNAN(b[i])) | |
844 | + r[i][j] << NotANumber(); | |
845 | + else | |
846 | + r[i][j] += b[i]; | |
847 | + } | |
848 | + break; | |
849 | + case 2: | |
850 | + if (r.getDim2Size() != b.size()) { | |
851 | + BOOST_THROW_EXCEPTION( | |
852 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
853 | + } | |
854 | + | |
855 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
856 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
857 | + if (isNAN(r[i][j]) || isNAN(b[j])) | |
858 | + r[i][j] << NotANumber(); | |
859 | + else | |
860 | + r[i][j] += b[j]; | |
861 | + } | |
862 | + break; | |
863 | + default: | |
864 | + BOOST_THROW_EXCEPTION( | |
865 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
866 | + } | |
867 | + return r; | |
902 | 868 | } |
903 | 869 | |
904 | 870 | template <typename Type1, typename Type2> |
905 | -AMDA::Parameters::Tab2DData<Type2> add(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) | |
906 | -{ | |
907 | - return add(b,a,mode); | |
871 | +AMDA::Parameters::Tab2DData<Type2> add(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) { | |
872 | + return add(b, a, mode); | |
908 | 873 | } |
909 | 874 | |
910 | 875 | /** |
911 | 876 | * @brief Operator + between Tab2D and vector |
912 | 877 | */ |
913 | 878 | template <typename Type1, typename Type2> |
914 | -AMDA::Parameters::Tab2DData<Type1> operator +(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) | |
915 | -{ | |
916 | - return add(a,b,1); | |
879 | +AMDA::Parameters::Tab2DData<Type1> operator+(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) { | |
880 | + return add(a, b, 1); | |
917 | 881 | } |
918 | 882 | |
919 | 883 | template <typename Type1, typename Type2> |
920 | -AMDA::Parameters::Tab2DData<Type2> operator +(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
921 | -{ | |
922 | - return add(a,b,1); | |
884 | +AMDA::Parameters::Tab2DData<Type2> operator+(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
885 | + return add(a, b, 1); | |
923 | 886 | } |
924 | 887 | |
925 | 888 | /** |
926 | 889 | * @brief Function sub between Tab2D and vector |
927 | 890 | */ |
928 | 891 | template <typename Type1, typename Type2> |
929 | -AMDA::Parameters::Tab2DData<Type1> sub(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) | |
930 | -{ | |
931 | - return add(a,(-1)*b,mode); | |
892 | +AMDA::Parameters::Tab2DData<Type1> sub(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) { | |
893 | + return add(a, (-1) * b, mode); | |
932 | 894 | } |
933 | 895 | |
934 | 896 | template <typename Type1, typename Type2> |
935 | -AMDA::Parameters::Tab2DData<Type2> sub(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) | |
936 | -{ | |
937 | - AMDA::Parameters::Tab2DData<Type2> r(b); | |
938 | - | |
939 | - switch(mode) | |
940 | - { | |
941 | - case 1 : | |
942 | - if (r.getDim1Size() != a.size()) { | |
943 | - BOOST_THROW_EXCEPTION( | |
944 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
945 | - } | |
946 | - | |
947 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
948 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
949 | - { | |
950 | - if (isNAN(r[i][j]) || isNAN(a[i])) | |
951 | - r[i][j] << NotANumber(); | |
952 | - else | |
953 | - r[i][j] = a[i] - r[i][j]; | |
954 | - } | |
955 | - break; | |
956 | - case 2 : | |
957 | - if (r.getDim2Size() != a.size()) { | |
958 | - BOOST_THROW_EXCEPTION( | |
959 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
960 | - } | |
961 | - | |
962 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
963 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
964 | - { | |
965 | - if (isNAN(r[i][j]) || isNAN(a[j])) | |
966 | - r[i][j] << NotANumber(); | |
967 | - else | |
968 | - r[i][j] = a[j] - r[i][j]; | |
969 | - } | |
970 | - break; | |
971 | - default: | |
972 | - BOOST_THROW_EXCEPTION( | |
973 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
974 | - } | |
975 | - return r; | |
897 | +AMDA::Parameters::Tab2DData<Type2> sub(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) { | |
898 | + AMDA::Parameters::Tab2DData<Type2> r(b); | |
899 | + | |
900 | + switch (mode) { | |
901 | + case 1: | |
902 | + if (r.getDim1Size() != a.size()) { | |
903 | + BOOST_THROW_EXCEPTION( | |
904 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
905 | + } | |
906 | + | |
907 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
908 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
909 | + if (isNAN(r[i][j]) || isNAN(a[i])) | |
910 | + r[i][j] << NotANumber(); | |
911 | + else | |
912 | + r[i][j] = a[i] - r[i][j]; | |
913 | + } | |
914 | + break; | |
915 | + case 2: | |
916 | + if (r.getDim2Size() != a.size()) { | |
917 | + BOOST_THROW_EXCEPTION( | |
918 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
919 | + } | |
920 | + | |
921 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
922 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
923 | + if (isNAN(r[i][j]) || isNAN(a[j])) | |
924 | + r[i][j] << NotANumber(); | |
925 | + else | |
926 | + r[i][j] = a[j] - r[i][j]; | |
927 | + } | |
928 | + break; | |
929 | + default: | |
930 | + BOOST_THROW_EXCEPTION( | |
931 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
932 | + } | |
933 | + return r; | |
976 | 934 | } |
977 | 935 | |
978 | 936 | /** |
979 | 937 | * @brief Operator - between Tab2D and vector |
980 | 938 | */ |
981 | 939 | template <typename Type1, typename Type2> |
982 | -AMDA::Parameters::Tab2DData<Type1> operator -(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) | |
983 | -{ | |
984 | - return sub(a,b,1); | |
940 | +AMDA::Parameters::Tab2DData<Type1> operator-(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) { | |
941 | + return sub(a, b, 1); | |
985 | 942 | } |
986 | 943 | |
987 | 944 | template <typename Type1, typename Type2> |
988 | -AMDA::Parameters::Tab2DData<Type2> operator -(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
989 | -{ | |
990 | - return sub(a,b,1); | |
945 | +AMDA::Parameters::Tab2DData<Type2> operator-(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
946 | + return sub(a, b, 1); | |
991 | 947 | } |
992 | 948 | |
993 | 949 | /** |
994 | 950 | * @brief Function mult between Tab2D and vector |
995 | 951 | */ |
996 | 952 | template <typename Type1, typename Type2> |
997 | -AMDA::Parameters::Tab2DData<Type1> mult(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) | |
998 | -{ | |
999 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
1000 | - | |
1001 | - switch (mode) | |
1002 | - { | |
1003 | - case 1 : | |
1004 | - if (r.getDim1Size() != b.size()) { | |
1005 | - BOOST_THROW_EXCEPTION( | |
1006 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1007 | - } | |
1008 | - | |
1009 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1010 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1011 | - { | |
1012 | - if (isNAN(r[i][j]) || isNAN(b[i])) | |
1013 | - r[i][j] << NotANumber(); | |
1014 | - else | |
1015 | - r[i][j] *= b[i]; | |
1016 | - } | |
1017 | - break; | |
1018 | - case 2: | |
1019 | - if (r.getDim2Size() != b.size()) { | |
1020 | - BOOST_THROW_EXCEPTION( | |
1021 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1022 | - } | |
1023 | - | |
1024 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1025 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1026 | - { | |
1027 | - if (isNAN(r[i][j]) || isNAN(b[j])) | |
1028 | - r[i][j] << NotANumber(); | |
1029 | - else | |
1030 | - r[i][j] *= b[j]; | |
1031 | - } | |
1032 | - break; | |
1033 | - default: | |
1034 | - BOOST_THROW_EXCEPTION( | |
1035 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
1036 | - } | |
1037 | - return r; | |
953 | +AMDA::Parameters::Tab2DData<Type1> mult(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) { | |
954 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
955 | + | |
956 | + switch (mode) { | |
957 | + case 1: | |
958 | + if (r.getDim1Size() != b.size()) { | |
959 | + BOOST_THROW_EXCEPTION( | |
960 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
961 | + } | |
962 | + | |
963 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
964 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
965 | + if (isNAN(r[i][j]) || isNAN(b[i])) | |
966 | + r[i][j] << NotANumber(); | |
967 | + else | |
968 | + r[i][j] *= b[i]; | |
969 | + } | |
970 | + break; | |
971 | + case 2: | |
972 | + if (r.getDim2Size() != b.size()) { | |
973 | + BOOST_THROW_EXCEPTION( | |
974 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
975 | + } | |
976 | + | |
977 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
978 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
979 | + if (isNAN(r[i][j]) || isNAN(b[j])) | |
980 | + r[i][j] << NotANumber(); | |
981 | + else | |
982 | + r[i][j] *= b[j]; | |
983 | + } | |
984 | + break; | |
985 | + default: | |
986 | + BOOST_THROW_EXCEPTION( | |
987 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
988 | + } | |
989 | + return r; | |
1038 | 990 | } |
1039 | 991 | |
1040 | 992 | template <typename Type1, typename Type2> |
1041 | -AMDA::Parameters::Tab2DData<Type2> mult(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) | |
1042 | -{ | |
1043 | - return mult(b,a,mode); | |
993 | +AMDA::Parameters::Tab2DData<Type2> mult(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) { | |
994 | + return mult(b, a, mode); | |
1044 | 995 | } |
1045 | 996 | |
1046 | 997 | /** |
1047 | 998 | * @brief Operator * between Tab2D and vector |
1048 | 999 | */ |
1049 | 1000 | template <typename Type1, typename Type2> |
1050 | -AMDA::Parameters::Tab2DData<Type1> operator *(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) | |
1051 | -{ | |
1052 | - return mult(a,b,1); | |
1001 | +AMDA::Parameters::Tab2DData<Type1> operator*(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) { | |
1002 | + return mult(a, b, 1); | |
1053 | 1003 | } |
1054 | 1004 | |
1055 | 1005 | template <typename Type1, typename Type2> |
1056 | -AMDA::Parameters::Tab2DData<Type2> operator *(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
1057 | -{ | |
1058 | - return mult(b,a,1); | |
1006 | +AMDA::Parameters::Tab2DData<Type2> operator*(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
1007 | + return mult(b, a, 1); | |
1059 | 1008 | } |
1060 | 1009 | |
1061 | 1010 | /** |
1062 | 1011 | * @brief Function div between Tab2D and vector |
1063 | 1012 | */ |
1064 | 1013 | template <typename Type1, typename Type2> |
1065 | -AMDA::Parameters::Tab2DData<Type1> div(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) | |
1066 | -{ | |
1067 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
1068 | - | |
1069 | - switch (mode) | |
1070 | - { | |
1071 | - case 1 : | |
1072 | - if (r.getDim1Size() != b.size()) { | |
1073 | - BOOST_THROW_EXCEPTION( | |
1074 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1075 | - } | |
1076 | - | |
1077 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1078 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1079 | - { | |
1080 | - if (isNAN(r[i][j]) || isNAN(b[i]) || (b[i] == 0)) | |
1081 | - r[i][j] << NotANumber(); | |
1082 | - else | |
1083 | - r[i][j] = r[i][j] / b[i]; | |
1084 | - } | |
1085 | - break; | |
1086 | - case 2 : | |
1087 | - if (r.getDim2Size() != b.size()) { | |
1088 | - BOOST_THROW_EXCEPTION( | |
1089 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1090 | - } | |
1091 | - | |
1092 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1093 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1094 | - { | |
1095 | - if (isNAN(r[i][j]) || isNAN(b[j]) || (b[j] == 0)) | |
1096 | - r[i][j] << NotANumber(); | |
1097 | - else | |
1098 | - r[i][j] = r[i][j] / b[j]; | |
1099 | - } | |
1100 | - break; | |
1101 | - default: | |
1102 | - BOOST_THROW_EXCEPTION( | |
1103 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
1104 | - } | |
1105 | - return r; | |
1014 | +AMDA::Parameters::Tab2DData<Type1> div(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b, int mode) { | |
1015 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
1016 | + | |
1017 | + switch (mode) { | |
1018 | + case 1: | |
1019 | + if (r.getDim1Size() != b.size()) { | |
1020 | + BOOST_THROW_EXCEPTION( | |
1021 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1022 | + } | |
1023 | + | |
1024 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
1025 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
1026 | + if (isNAN(r[i][j]) || isNAN(b[i]) || (b[i] == 0)) | |
1027 | + r[i][j] << NotANumber(); | |
1028 | + else | |
1029 | + r[i][j] = r[i][j] / b[i]; | |
1030 | + } | |
1031 | + break; | |
1032 | + case 2: | |
1033 | + if (r.getDim2Size() != b.size()) { | |
1034 | + BOOST_THROW_EXCEPTION( | |
1035 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1036 | + } | |
1037 | + | |
1038 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
1039 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
1040 | + if (isNAN(r[i][j]) || isNAN(b[j]) || (b[j] == 0)) | |
1041 | + r[i][j] << NotANumber(); | |
1042 | + else | |
1043 | + r[i][j] = r[i][j] / b[j]; | |
1044 | + } | |
1045 | + break; | |
1046 | + default: | |
1047 | + BOOST_THROW_EXCEPTION( | |
1048 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
1049 | + } | |
1050 | + return r; | |
1106 | 1051 | } |
1107 | 1052 | |
1108 | 1053 | template <typename Type1, typename Type2> |
1109 | -AMDA::Parameters::Tab2DData<Type2> div(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) | |
1110 | -{ | |
1111 | - AMDA::Parameters::Tab2DData<Type2> r(b); | |
1112 | - | |
1113 | - switch (mode) | |
1114 | - { | |
1115 | - case 1 : | |
1116 | - if (r.getDim1Size() != a.size()) { | |
1117 | - BOOST_THROW_EXCEPTION( | |
1118 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1119 | - } | |
1120 | - | |
1121 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1122 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1123 | - { | |
1124 | - if (isNAN(r[i][j]) || isNAN(a[i]) || (r[i][j] == 0)) | |
1125 | - r[i][j] << NotANumber(); | |
1126 | - else | |
1127 | - r[i][j] = a[i] / r[i][j]; | |
1128 | - } | |
1129 | - break; | |
1130 | - case 2 : | |
1131 | - if (r.getDim2Size() != a.size()) { | |
1132 | - BOOST_THROW_EXCEPTION( | |
1133 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1134 | - } | |
1135 | - | |
1136 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1137 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1138 | - { | |
1139 | - if (isNAN(r[i][j]) || isNAN(a[j]) || (r[i][j] == 0)) | |
1140 | - r[i][j] << NotANumber(); | |
1141 | - else | |
1142 | - r[i][j] = a[j] / r[i][j]; | |
1143 | - } | |
1144 | - break; | |
1145 | - default: | |
1146 | - BOOST_THROW_EXCEPTION( | |
1147 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
1148 | - } | |
1149 | - return r; | |
1054 | +AMDA::Parameters::Tab2DData<Type2> div(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b, int mode) { | |
1055 | + AMDA::Parameters::Tab2DData<Type2> r(b); | |
1056 | + | |
1057 | + switch (mode) { | |
1058 | + case 1: | |
1059 | + if (r.getDim1Size() != a.size()) { | |
1060 | + BOOST_THROW_EXCEPTION( | |
1061 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1062 | + } | |
1063 | + | |
1064 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
1065 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
1066 | + if (isNAN(r[i][j]) || isNAN(a[i]) || (r[i][j] == 0)) | |
1067 | + r[i][j] << NotANumber(); | |
1068 | + else | |
1069 | + r[i][j] = a[i] / r[i][j]; | |
1070 | + } | |
1071 | + break; | |
1072 | + case 2: | |
1073 | + if (r.getDim2Size() != a.size()) { | |
1074 | + BOOST_THROW_EXCEPTION( | |
1075 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1076 | + } | |
1077 | + | |
1078 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
1079 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
1080 | + if (isNAN(r[i][j]) || isNAN(a[j]) || (r[i][j] == 0)) | |
1081 | + r[i][j] << NotANumber(); | |
1082 | + else | |
1083 | + r[i][j] = a[j] / r[i][j]; | |
1084 | + } | |
1085 | + break; | |
1086 | + default: | |
1087 | + BOOST_THROW_EXCEPTION( | |
1088 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
1089 | + } | |
1090 | + return r; | |
1150 | 1091 | } |
1151 | 1092 | |
1152 | 1093 | /** |
1153 | 1094 | * @brief Operator / between Tab2D and vector |
1154 | 1095 | */ |
1155 | 1096 | template <typename Type1, typename Type2> |
1156 | -AMDA::Parameters::Tab2DData<Type1> operator /(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) | |
1157 | -{ | |
1158 | - return div(a,b,1); | |
1097 | +AMDA::Parameters::Tab2DData<Type1> operator/(const AMDA::Parameters::Tab2DData<Type1>& a, std::vector<Type2> b) { | |
1098 | + return div(a, b, 1); | |
1159 | 1099 | } |
1160 | 1100 | |
1161 | 1101 | template <typename Type1, typename Type2> |
1162 | -AMDA::Parameters::Tab2DData<Type2> operator /(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
1163 | -{ | |
1164 | - return div(b,a,1); | |
1102 | +AMDA::Parameters::Tab2DData<Type2> operator/(std::vector<Type1> a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
1103 | + return div(b, a, 1); | |
1165 | 1104 | } |
1166 | 1105 | |
1167 | 1106 | /** |
1168 | 1107 | * @brief Operator + between two Tab2D |
1169 | 1108 | */ |
1170 | 1109 | template <typename Type1, typename Type2> |
1171 | -AMDA::Parameters::Tab2DData<Type1> operator +(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
1172 | -{ | |
1173 | - if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) { | |
1174 | - BOOST_THROW_EXCEPTION( | |
1175 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1176 | - } | |
1177 | - | |
1178 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
1179 | - | |
1180 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1181 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1182 | - { | |
1183 | - if (isNAN(a[i][j]) || isNAN(b[i][j])) | |
1184 | - r[i][j] << NotANumber(); | |
1185 | - else | |
1186 | - r[i][j] = a[i][j] + b[i][j]; | |
1187 | - } | |
1110 | +AMDA::Parameters::Tab2DData<Type1> operator+(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
1111 | + if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) { | |
1112 | + BOOST_THROW_EXCEPTION( | |
1113 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1114 | + } | |
1115 | + | |
1116 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
1117 | + | |
1118 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
1119 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
1120 | + if (isNAN(a[i][j]) || isNAN(b[i][j])) | |
1121 | + r[i][j] << NotANumber(); | |
1122 | + else | |
1123 | + r[i][j] = a[i][j] + b[i][j]; | |
1124 | + } | |
1188 | 1125 | |
1189 | - return r; | |
1126 | + return r; | |
1190 | 1127 | } |
1191 | 1128 | |
1192 | 1129 | /** |
1193 | 1130 | * @brief Operator - between two Tab2D |
1194 | 1131 | */ |
1195 | 1132 | template <typename Type1, typename Type2> |
1196 | -AMDA::Parameters::Tab2DData<Type1> operator -(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
1197 | -{ | |
1198 | - if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) { | |
1199 | - BOOST_THROW_EXCEPTION( | |
1200 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1201 | - } | |
1202 | - | |
1203 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
1204 | - | |
1205 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1206 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1207 | - { | |
1208 | - if (isNAN(a[i][j]) || isNAN(b[i][j])) | |
1209 | - r[i][j] << NotANumber(); | |
1210 | - else | |
1211 | - r[i][j] = a[i][j] - b[i][j]; | |
1212 | - } | |
1213 | - return r; | |
1133 | +AMDA::Parameters::Tab2DData<Type1> operator-(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
1134 | + if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) { | |
1135 | + BOOST_THROW_EXCEPTION( | |
1136 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1137 | + } | |
1138 | + | |
1139 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
1140 | + | |
1141 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
1142 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
1143 | + if (isNAN(a[i][j]) || isNAN(b[i][j])) | |
1144 | + r[i][j] << NotANumber(); | |
1145 | + else | |
1146 | + r[i][j] = a[i][j] - b[i][j]; | |
1147 | + } | |
1148 | + return r; | |
1214 | 1149 | } |
1215 | 1150 | |
1216 | 1151 | /** |
1217 | 1152 | * @brief Operator * between two Tab2D |
1218 | 1153 | */ |
1219 | 1154 | template <typename Type1, typename Type2> |
1220 | -AMDA::Parameters::Tab2DData<Type1> operator *(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
1221 | -{ | |
1222 | - if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) { | |
1223 | - BOOST_THROW_EXCEPTION( | |
1224 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1225 | - } | |
1226 | - | |
1227 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
1228 | - | |
1229 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1230 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1231 | - { | |
1232 | - if (isNAN(a[i][j]) || isNAN(b[i][j])) | |
1233 | - r[i][j] << NotANumber(); | |
1234 | - else | |
1235 | - r[i][j] = a[i][j] * b[i][j]; | |
1236 | - } | |
1237 | - return r; | |
1155 | +AMDA::Parameters::Tab2DData<Type1> operator*(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
1156 | + if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) { | |
1157 | + BOOST_THROW_EXCEPTION( | |
1158 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1159 | + } | |
1160 | + | |
1161 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
1162 | + | |
1163 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
1164 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
1165 | + if (isNAN(a[i][j]) || isNAN(b[i][j])) | |
1166 | + r[i][j] << NotANumber(); | |
1167 | + else | |
1168 | + r[i][j] = a[i][j] * b[i][j]; | |
1169 | + } | |
1170 | + return r; | |
1238 | 1171 | } |
1239 | 1172 | |
1240 | 1173 | /** |
1241 | 1174 | * @brief Operator + between two Tab2D |
1242 | 1175 | */ |
1243 | 1176 | template <typename Type1, typename Type2> |
1244 | -AMDA::Parameters::Tab2DData<Type1> operator /(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) | |
1245 | -{ | |
1246 | - if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) { | |
1247 | - BOOST_THROW_EXCEPTION( | |
1248 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1249 | - } | |
1250 | - | |
1251 | - AMDA::Parameters::Tab2DData<Type1> r(a); | |
1252 | - | |
1253 | - for(int i = 0; i < r.getDim1Size(); ++i) | |
1254 | - for(int j = 0; j < r.getDim2Size(); ++j) | |
1255 | - { | |
1256 | - if (isNAN(a[i][j]) || isNAN(b[i][j]) || (b[i][j] == 0)) | |
1257 | - r[i][j] << NotANumber(); | |
1258 | - else | |
1259 | - r[i][j] = a[i][j] / b[i][j]; | |
1260 | - } | |
1261 | - return r; | |
1177 | +AMDA::Parameters::Tab2DData<Type1> operator/(const AMDA::Parameters::Tab2DData<Type1>& a, const AMDA::Parameters::Tab2DData<Type2>& b) { | |
1178 | + if ((a.getDim1Size() != b.getDim1Size()) || (a.getDim2Size() != b.getDim2Size())) { | |
1179 | + BOOST_THROW_EXCEPTION( | |
1180 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due to incompatibility in data dimensions")); | |
1181 | + } | |
1182 | + | |
1183 | + AMDA::Parameters::Tab2DData<Type1> r(a); | |
1184 | + | |
1185 | + for (int i = 0; i < r.getDim1Size(); ++i) | |
1186 | + for (int j = 0; j < r.getDim2Size(); ++j) { | |
1187 | + if (isNAN(a[i][j]) || isNAN(b[i][j]) || (b[i][j] == 0)) | |
1188 | + r[i][j] << NotANumber(); | |
1189 | + else | |
1190 | + r[i][j] = a[i][j] / b[i][j]; | |
1191 | + } | |
1192 | + return r; | |
1262 | 1193 | } |
1263 | 1194 | |
1264 | 1195 | /** |
1265 | 1196 | * @brief Function total on all components of a vector => result is a scalar |
1266 | 1197 | */ |
1267 | 1198 | template <typename Type> |
1268 | -Type total(const std::vector<Type>& a) | |
1269 | -{ | |
1270 | - Type sum; | |
1271 | - sum << NotANumber(); | |
1272 | - | |
1273 | - for(int j = 0; j < a.size(); ++j) | |
1274 | - { | |
1275 | - if (isFinite(a[j])) | |
1276 | - { | |
1277 | - if (isNAN(sum)) | |
1278 | - sum = a[j]; | |
1279 | - else | |
1280 | - sum += a[j]; | |
1281 | - } | |
1282 | - } | |
1283 | - return sum; | |
1199 | +Type total(const std::vector<Type>& a) { | |
1200 | + Type sum; | |
1201 | + sum << NotANumber(); | |
1202 | + | |
1203 | + for (int j = 0; j < a.size(); ++j) { | |
1204 | + if (isFinite(a[j])) { | |
1205 | + if (isNAN(sum)) | |
1206 | + sum = a[j]; | |
1207 | + else | |
1208 | + sum += a[j]; | |
1209 | + } | |
1210 | + } | |
1211 | + return sum; | |
1284 | 1212 | } |
1285 | 1213 | |
1286 | 1214 | /** |
1287 | 1215 | * @brief Function total on all components of a Tab2D => result is a scalar |
1288 | 1216 | */ |
1289 | 1217 | template <typename Type> |
1290 | -Type total(const AMDA::Parameters::Tab2DData<Type>& a) | |
1291 | -{ | |
1292 | - Type sum; | |
1293 | - sum << NotANumber(); | |
1294 | - | |
1295 | - for(int i = 0; i < a.getDim1Size(); ++i) | |
1296 | - for(int j = 0; j < a.getDim2Size(); ++j) | |
1297 | - { | |
1298 | - if (isFinite(a[i][j])) | |
1299 | - { | |
1300 | - if (isNAN(sum)) | |
1301 | - sum = a[i][j]; | |
1302 | - else | |
1303 | - sum += a[i][j]; | |
1304 | - } | |
1305 | - } | |
1306 | - return sum; | |
1218 | +Type total(const AMDA::Parameters::Tab2DData<Type>& a) { | |
1219 | + Type sum; | |
1220 | + sum << NotANumber(); | |
1221 | + | |
1222 | + for (int i = 0; i < a.getDim1Size(); ++i) | |
1223 | + for (int j = 0; j < a.getDim2Size(); ++j) { | |
1224 | + if (isFinite(a[i][j])) { | |
1225 | + if (isNAN(sum)) | |
1226 | + sum = a[i][j]; | |
1227 | + else | |
1228 | + sum += a[i][j]; | |
1229 | + } | |
1230 | + } | |
1231 | + return sum; | |
1307 | 1232 | } |
1308 | 1233 | |
1309 | 1234 | /** |
... | ... | @@ -1312,131 +1237,122 @@ Type total(const AMDA::Parameters::Tab2DData<Type>& a) |
1312 | 1237 | * mode = 2 => sum on columns |
1313 | 1238 | */ |
1314 | 1239 | template <typename Type> |
1315 | -std::vector<Type> total(const AMDA::Parameters::Tab2DData<Type>& a,int mode) | |
1316 | -{ | |
1317 | - std::vector<Type> sum; | |
1318 | - | |
1319 | - switch (mode) | |
1320 | - { | |
1321 | - case 1 : | |
1322 | - for(int j = 0; j < a.getDim2Size(); ++j) | |
1323 | - { | |
1324 | - Type elem; | |
1325 | - elem << NotANumber(); | |
1326 | - for(int i = 0; i < a.getDim1Size(); ++i) | |
1327 | - { | |
1328 | - if (isFinite(a[i][j])) | |
1329 | - { | |
1330 | - if (isNAN(elem)) | |
1331 | - elem = a[i][j]; | |
1332 | - else | |
1333 | - elem += a[i][j]; | |
1334 | - } | |
1335 | - } | |
1336 | - sum.push_back(elem); | |
1337 | - } | |
1338 | - break; | |
1339 | - case 2 : | |
1340 | - for(int i = 0; i < a.getDim1Size(); ++i) | |
1341 | - { | |
1342 | - Type elem; | |
1343 | - elem << NotANumber(); | |
1344 | - for(int j = 0; j < a.getDim2Size(); ++j) | |
1345 | - { | |
1346 | - if (isFinite(a[i][j])) | |
1347 | - { | |
1348 | - if (isNAN(elem)) | |
1349 | - elem = a[i][j]; | |
1350 | - else | |
1351 | - elem += a[i][j]; | |
1352 | - } | |
1353 | - } | |
1354 | - sum.push_back(elem); | |
1355 | - } | |
1356 | - break; | |
1357 | - default: | |
1358 | - BOOST_THROW_EXCEPTION( | |
1359 | - AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
1360 | - } | |
1361 | - | |
1362 | - return sum; | |
1240 | +std::vector<Type> total(const AMDA::Parameters::Tab2DData<Type>& a, int mode) { | |
1241 | + std::vector<Type> sum; | |
1242 | + | |
1243 | + switch (mode) { | |
1244 | + case 1: | |
1245 | + for (int j = 0; j < a.getDim2Size(); ++j) { | |
1246 | + Type elem; | |
1247 | + elem << NotANumber(); | |
1248 | + for (int i = 0; i < a.getDim1Size(); ++i) { | |
1249 | + if (isFinite(a[i][j])) { | |
1250 | + if (isNAN(elem)) | |
1251 | + elem = a[i][j]; | |
1252 | + else | |
1253 | + elem += a[i][j]; | |
1254 | + } | |
1255 | + } | |
1256 | + sum.push_back(elem); | |
1257 | + } | |
1258 | + break; | |
1259 | + case 2: | |
1260 | + for (int i = 0; i < a.getDim1Size(); ++i) { | |
1261 | + Type elem; | |
1262 | + elem << NotANumber(); | |
1263 | + for (int j = 0; j < a.getDim2Size(); ++j) { | |
1264 | + if (isFinite(a[i][j])) { | |
1265 | + if (isNAN(elem)) | |
1266 | + elem = a[i][j]; | |
1267 | + else | |
1268 | + elem += a[i][j]; | |
1269 | + } | |
1270 | + } | |
1271 | + sum.push_back(elem); | |
1272 | + } | |
1273 | + break; | |
1274 | + default: | |
1275 | + BOOST_THROW_EXCEPTION( | |
1276 | + AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Operation not allowed due a not implemented mode")); | |
1277 | + } | |
1278 | + | |
1279 | + return sum; | |
1363 | 1280 | } |
1364 | 1281 | |
1365 | - | |
1366 | 1282 | template <typename Type1, typename Type2> |
1367 | -std::vector<Type1> operator +(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1368 | - std::vector<Type1> av(a); | |
1369 | - std::vector<Type1> bv(b); | |
1370 | - return av+bv; | |
1283 | +std::vector<Type1> operator+(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1284 | + std::vector<Type1> av(a); | |
1285 | + std::vector<Type1> bv(b); | |
1286 | + return av + bv; | |
1371 | 1287 | } |
1372 | 1288 | |
1373 | 1289 | template <typename Type1, typename Type2> |
1374 | -std::vector<Type1> operator +(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1375 | - std::vector<Type2> bv(b); | |
1376 | - return a+bv; | |
1290 | +std::vector<Type1> operator+(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1291 | + std::vector<Type2> bv(b); | |
1292 | + return a + bv; | |
1377 | 1293 | } |
1378 | 1294 | |
1379 | 1295 | template <typename Type1, typename Type2> |
1380 | -std::vector<Type1> operator +(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) { | |
1381 | - std::vector<Type1> av(a); | |
1382 | - return av+b; | |
1296 | +std::vector<Type1> operator+(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) { | |
1297 | + std::vector<Type1> av(a); | |
1298 | + return av + b; | |
1383 | 1299 | } |
1384 | 1300 | |
1385 | 1301 | template <typename Type1, typename Type2> |
1386 | -std::vector<Type1> operator *(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1387 | - std::vector<Type1> av(a); | |
1388 | - std::vector<Type1> bv(b); | |
1389 | - return av*bv; | |
1302 | +std::vector<Type1> operator*(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1303 | + std::vector<Type1> av(a); | |
1304 | + std::vector<Type1> bv(b); | |
1305 | + return av*bv; | |
1390 | 1306 | } |
1391 | 1307 | |
1392 | 1308 | template <typename Type1, typename Type2> |
1393 | -std::vector<Type1> operator *(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1394 | - std::vector<Type2> bv(b); | |
1395 | - return a*bv; | |
1309 | +std::vector<Type1> operator*(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1310 | + std::vector<Type2> bv(b); | |
1311 | + return a*bv; | |
1396 | 1312 | } |
1397 | 1313 | |
1398 | 1314 | template <typename Type1, typename Type2> |
1399 | -std::vector<Type1> operator *(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) { | |
1400 | - std::vector<Type1> av(a); | |
1401 | - return av*b; | |
1315 | +std::vector<Type1> operator*(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) { | |
1316 | + std::vector<Type1> av(a); | |
1317 | + return av*b; | |
1402 | 1318 | } |
1403 | 1319 | |
1404 | 1320 | template <typename Type1, typename Type2> |
1405 | -std::vector<Type1> operator -(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1406 | - std::vector<Type1> av(a); | |
1407 | - std::vector<Type1> bv(b); | |
1408 | - return av-bv; | |
1321 | +std::vector<Type1> operator-(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1322 | + std::vector<Type1> av(a); | |
1323 | + std::vector<Type1> bv(b); | |
1324 | + return av - bv; | |
1409 | 1325 | } |
1410 | 1326 | |
1411 | 1327 | template <typename Type1, typename Type2> |
1412 | -std::vector<Type1> operator -(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1413 | - std::vector<Type2> bv(b); | |
1414 | - return a-bv; | |
1328 | +std::vector<Type1> operator-(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1329 | + std::vector<Type2> bv(b); | |
1330 | + return a - bv; | |
1415 | 1331 | } |
1416 | 1332 | |
1417 | 1333 | template <typename Type1, typename Type2> |
1418 | -std::vector<Type1> operator -(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) { | |
1419 | - std::vector<Type1> av(a); | |
1420 | - return av-b; | |
1334 | +std::vector<Type1> operator-(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) { | |
1335 | + std::vector<Type1> av(a); | |
1336 | + return av - b; | |
1421 | 1337 | } |
1422 | 1338 | |
1423 | 1339 | template <typename Type1, typename Type2> |
1424 | -std::vector<Type1> operator /(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1425 | - std::vector<Type1> av(a); | |
1426 | - std::vector<Type1> bv(b); | |
1427 | - return av/bv; | |
1340 | +std::vector<Type1> operator/(AMDA::Parameters::TabRow<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1341 | + std::vector<Type1> av(a); | |
1342 | + std::vector<Type1> bv(b); | |
1343 | + return av / bv; | |
1428 | 1344 | } |
1429 | 1345 | |
1430 | 1346 | template <typename Type1, typename Type2> |
1431 | -std::vector<Type1> operator /(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1432 | - std::vector<Type2> bv(b); | |
1433 | - return a/bv; | |
1347 | +std::vector<Type1> operator/(std::vector<Type1> a, AMDA::Parameters::TabRow<Type2> b) { | |
1348 | + std::vector<Type2> bv(b); | |
1349 | + return a / bv; | |
1434 | 1350 | } |
1435 | 1351 | |
1436 | 1352 | template <typename Type1, typename Type2> |
1437 | -std::vector<Type1> operator /(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) { | |
1438 | - std::vector<Type1> av(a); | |
1439 | - return av/b; | |
1353 | +std::vector<Type1> operator/(AMDA::Parameters::TabRow<Type1> a, std::vector<Type2> b) { | |
1354 | + std::vector<Type1> av(a); | |
1355 | + return av / b; | |
1440 | 1356 | } |
1441 | 1357 | |
1442 | 1358 | #endif /* LOGICALDATATYPE_HH_ */ | ... | ... |
src/Parameters/StatisticData.hh
... | ... | @@ -36,7 +36,7 @@ void pushStatisticDataInVectorString(std::vector<std::string> &result, std::vect |
36 | 36 | //push coverage |
37 | 37 | if (isCoverageIndependantOfResultType && (coverage.size() >= 1)) |
38 | 38 | return; |
39 | - double c = (double)data._nbDataProcessed / (double)ideal; | |
39 | + double c = (double)data._nbDataProcessed / ((double)ideal+1); | |
40 | 40 | if (c < 0.) |
41 | 41 | c = 0.; |
42 | 42 | if (c > 1.) | ... | ... |
test/FitNesseRoot/ReleaseS/SecondPart/ReLease1/SprinT2/UserStory43/.txt
test/data/functions.xml
... | ... | @@ -92,6 +92,17 @@ |
92 | 92 | <info_brief>Cross product</info_brief> |
93 | 93 | <new_kernel>cross</new_kernel> |
94 | 94 | </function> |
95 | + | |
96 | + <function name="angle(,)" args="2" kind="vectors"> | |
97 | + <info_brief>Angle between two vectors</info_brief> | |
98 | + <new_kernel>angle</new_kernel> | |
99 | + </function> | |
100 | + | |
101 | + <function name="magnitude_(,)" args="2" kind="vectors"> | |
102 | + <info_brief>magnitude of a vector</info_brief> | |
103 | + <new_kernel>magnitude</new_kernel> | |
104 | + </function> | |
105 | + | |
95 | 106 | <function name="dot(,)" args="2" kind="vectors"> |
96 | 107 | <info_brief>Dot product</info_brief> |
97 | 108 | <new_kernel>dot</new_kernel> | ... | ... |