Commit 351058d56f03f1c8d2b490e015c8d2f9880b57d4

Authored by Elena.Budnik
1 parent 20fef3b6

total() for vector

Showing 1 changed file with 22 additions and 0 deletions   Show diff stats
src/Parameters/DataTypeMath.hh
... ... @@ -1131,6 +1131,28 @@ AMDA::Parameters::Tab2DData<Type1> operator /(const AMDA::Parameters::Tab2DData<
1131 1131 }
1132 1132  
1133 1133 /**
  1134 + * @brief Function total on all components of a vector => result is a scalar
  1135 + */
  1136 +template <typename Type>
  1137 +Type total(const std::vector<Type>& a)
  1138 +{
  1139 + Type sum;
  1140 + sum << NotANumber();
  1141 +
  1142 + for(int j = 0; j < a.size(); ++j)
  1143 + {
  1144 + if (isFinite(a[j]))
  1145 + {
  1146 + if (isNAN(sum))
  1147 + sum = a[j];
  1148 + else
  1149 + sum += a[j];
  1150 + }
  1151 + }
  1152 + return sum;
  1153 +}
  1154 +
  1155 +/**
1134 1156 * @brief Function total on all components of a Tab2D => result is a scalar
1135 1157 */
1136 1158 template <typename Type>
... ...