Commit 8aa97375b87ad9874bb265ae4b4d796d783f2615
1 parent
f1326d28
Exists in
master
and in
87 other branches
Add some missing operators between vector and scalar
Showing
1 changed file
with
64 additions
and
31 deletions
Show diff stats
src/Parameters/DataTypeMath.hh
... | ... | @@ -156,7 +156,7 @@ |
156 | 156 | */ |
157 | 157 | template <typename Type1, typename Type2> |
158 | 158 | std::vector<Type1> operator -(std::vector<Type1> a, std::vector<Type2> b) { |
159 | - std::vector<Type1> r; | |
159 | + std::vector<Type1> r; | |
160 | 160 | if(a.size() != b.size()) { |
161 | 161 | BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_OPER_NOT_ALLOWED) << AMDA::ex_msg("Subtract two vector of different size")); |
162 | 162 | } |
... | ... | @@ -281,14 +281,27 @@ |
281 | 281 | // vector with scalar operation |
282 | 282 | |
283 | 283 | /** |
284 | - * @brief Operator addition between a vector and a scalar | |
284 | + * @brief Operator division between a vector and a scalar | |
285 | 285 | * @details all member of vector are divided by the scalar |
286 | 286 | */ |
287 | - template <typename Type> | |
288 | - std::vector<Type> operator /(std::vector<Type> a, double f) { | |
289 | - std::vector<Type> r; | |
290 | - for(typename std::vector<Type>::iterator it = a.begin(); it != a.end(); ++it) { | |
291 | - r.push_back((Type)(*it / f)); | |
287 | + template <typename Type1, typename Type2> | |
288 | + std::vector<Type1> operator /(std::vector<Type1> a, Type2 b) { | |
289 | + std::vector<Type1> r; | |
290 | + for(typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
291 | + r.push_back((Type1)(*it / b)); | |
292 | + } | |
293 | + return r; | |
294 | + } | |
295 | + | |
296 | + /** | |
297 | + * @brief Operator division between a scalar and a vector | |
298 | + * @details apply the division on each vector component | |
299 | + */ | |
300 | + template <typename Type1, typename Type2> | |
301 | + std::vector<Type2> operator /(Type1 a, std::vector<Type2> b) { | |
302 | + std::vector<Type2> r; | |
303 | + for(typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
304 | + r.push_back((Type2)(a / *it)); | |
292 | 305 | } |
293 | 306 | return r; |
294 | 307 | } |
... | ... | @@ -298,47 +311,63 @@ |
298 | 311 | * @brief Operator addition between a vector and a scalar |
299 | 312 | * @details all member of vector are added with the scalar |
300 | 313 | */ |
301 | - template <typename Type> | |
302 | - std::vector<Type> operator +(std::vector<Type> a, double f) { | |
303 | - std::vector<Type> r; | |
304 | - for(typename std::vector<Type>::iterator it = a.begin(); it != a.end(); ++it) { | |
305 | - r.push_back((Type)(*it + f)); | |
314 | + template <typename Type1, typename Type2> | |
315 | + std::vector<Type1> operator +(std::vector<Type1> a, Type2 b) { | |
316 | + std::vector<Type1> r; | |
317 | + for(typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
318 | + r.push_back((Type1)(*it + b)); | |
306 | 319 | } |
307 | 320 | return r; |
308 | 321 | } |
309 | 322 | |
323 | + /** | |
324 | + * @brief Operator addition between a scalar and a vector | |
325 | + * @details all member of vector are added with the scalar | |
326 | + */ | |
327 | + template <typename Type1, typename Type2> | |
328 | + std::vector<Type2> operator +( Type1 a, std::vector<Type2> b) { | |
329 | + std::vector<Type2> r; | |
330 | + for(typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
331 | + r.push_back((Type2)(a + *it)); | |
332 | + } | |
333 | + return r; | |
334 | + } | |
310 | 335 | |
311 | 336 | /** |
312 | - * @brief Operator subtraction between a scalar and a vector | |
313 | - * @details all member of vector are subtracted with the scalar | |
337 | + * @brief Operator subtraction between a vector and a scalar | |
338 | + * @details scalar is substracted to all vector components | |
314 | 339 | */ |
315 | - template <typename Type> | |
316 | - std::vector<Type> operator -( double f, std::vector<Type> a) { | |
317 | - std::vector<Type> r; | |
318 | - for(typename std::vector<Type>::iterator it = a.begin(); it != a.end(); ++it) { | |
319 | - r.push_back(f-*it); | |
340 | + template <typename Type1, typename Type2> | |
341 | + std::vector<Type1> operator -(std::vector<Type1> a, Type2 b) { | |
342 | + std::vector<Type1> r; | |
343 | + for(typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { | |
344 | + r.push_back((Type1)(*it-b)); | |
320 | 345 | } |
321 | 346 | return r; |
322 | 347 | } |
323 | 348 | |
324 | 349 | /** |
325 | - * @brief Operator addition between a scalar and a vector | |
326 | - * @details all member of vector are added with the scalar | |
350 | + * @brief Operator subtraction between a scalar and a vector | |
351 | + * @details all member of vector are subtracted with the scalar | |
327 | 352 | */ |
328 | - template <typename Type> | |
329 | - std::vector<Type> operator +( double f, std::vector<Type> a) { | |
330 | - return a + f; | |
353 | + template <typename Type1, typename Type2> | |
354 | + std::vector<Type2> operator -(Type1 a, std::vector<Type2> b) { | |
355 | + std::vector<Type2> r; | |
356 | + for(typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
357 | + r.push_back((Type2)(a-*it)); | |
358 | + } | |
359 | + return r; | |
331 | 360 | } |
332 | 361 | |
333 | 362 | /** |
334 | 363 | * @brief Operator product between a vector and a scalar |
335 | - * @details all member of vector are added by the scalar | |
364 | + * @details product applied in all member of vector | |
336 | 365 | */ |
337 | - template <typename Type1> | |
338 | - std::vector<Type1> operator *(std::vector<Type1> a, double f) { | |
366 | + template <typename Type1, typename Type2> | |
367 | + std::vector<Type1> operator *(std::vector<Type1> a, Type2 b) { | |
339 | 368 | std::vector<Type1> r; |
340 | 369 | for(typename std::vector<Type1>::iterator it = a.begin(); it != a.end(); ++it) { |
341 | - r.push_back(*it * f); | |
370 | + r.push_back((Type1)((*it) * b)); | |
342 | 371 | } |
343 | 372 | return r; |
344 | 373 | } |
... | ... | @@ -347,9 +376,13 @@ |
347 | 376 | * @brief Operator product between a scalar and a vector |
348 | 377 | * @details all member of vector are added by the scalar |
349 | 378 | */ |
350 | - template <typename Type> | |
351 | - std::vector<Type> operator *( double f, std::vector<Type> a) { | |
352 | - return a * f; | |
379 | + template <typename Type1, typename Type2> | |
380 | + std::vector<Type2> operator *( Type1 a, std::vector<Type2> b) { | |
381 | + std::vector<Type2> r; | |
382 | + for(typename std::vector<Type2>::iterator it = b.begin(); it != b.end(); ++it) { | |
383 | + r.push_back((Type2)(a * (*it))); | |
384 | + } | |
385 | + return r; | |
353 | 386 | } |
354 | 387 | |
355 | 388 | ... | ... |