From 351058d56f03f1c8d2b490e015c8d2f9880b57d4 Mon Sep 17 00:00:00 2001 From: Elena.Budnik <ebudnik@irap.omp.eu> Date: Thu, 31 Jan 2019 17:02:25 +0100 Subject: [PATCH] total() for vector --- src/Parameters/DataTypeMath.hh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+), 0 deletions(-) diff --git a/src/Parameters/DataTypeMath.hh b/src/Parameters/DataTypeMath.hh index 2d45c0a..df6b541 100644 --- a/src/Parameters/DataTypeMath.hh +++ b/src/Parameters/DataTypeMath.hh @@ -1131,6 +1131,28 @@ AMDA::Parameters::Tab2DData<Type1> operator /(const AMDA::Parameters::Tab2DData< } /** + * @brief Function total on all components of a vector => result is a scalar + */ +template <typename Type> +Type total(const std::vector<Type>& a) +{ + Type sum; + sum << NotANumber(); + + for(int j = 0; j < a.size(); ++j) + { + if (isFinite(a[j])) + { + if (isNAN(sum)) + sum = a[j]; + else + sum += a[j]; + } + } + return sum; +} + +/** * @brief Function total on all components of a Tab2D => result is a scalar */ template <typename Type> -- libgit2 0.21.2