Commit 0c988395 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

varrayMinMaxSumMV(): refactored.

parent 81a77736
......@@ -59,9 +59,21 @@ size_t
fieldMinMaxSumMV(const Field &field, double &min, double &max, double &sum)
{
if (field.memType == MemType::Float)
return varrayMinMaxSumMV(field.size, field.vec_f, (float)field.missval, min, max, sum);
{
auto mms = varrayMinMaxSumMV(field.size, field.vec_f, (float)field.missval, MinMaxSum(min, max, sum));
min = mms.min;
max = mms.max;
sum = mms.sum;
return mms.n;
}
else
return varrayMinMaxSumMV(field.size, field.vec_d, field.missval, min, max, sum);
{
auto mms = varrayMinMaxSumMV(field.size, field.vec_d, field.missval, MinMaxSum(min, max, sum));
min = mms.min;
max = mms.max;
sum = mms.sum;
return mms.n;
}
}
static void
......
......@@ -81,12 +81,11 @@ varrayMinMaxMV(const size_t len, const Varray<double> &array, const double missv
template <typename T>
MinMaxSum
varrayMinMaxSum(const size_t len, const Varray<T> &array, MinMaxSum mmsinit)
varrayMinMaxSum(const size_t len, const Varray<T> &array, MinMaxSum mms)
{
// rmin, rmax and rsum will be initialized in Info
T rmin = mmsinit.min;
T rmax = mmsinit.max;
auto rsum = mmsinit.sum;
T rmin = mms.min;
T rmax = mms.max;
auto rsum = mms.sum;
for (size_t i = 0; i < len; ++i)
{
......@@ -100,37 +99,59 @@ varrayMinMaxSum(const size_t len, const Varray<T> &array, MinMaxSum mmsinit)
}
// Explicit instantiation
template MinMaxSum varrayMinMaxSum(const size_t len, const Varray<float> &array, MinMaxSum mmsinit);
template MinMaxSum varrayMinMaxSum(const size_t len, const Varray<double> &array, MinMaxSum mmsinit);
template MinMaxSum varrayMinMaxSum(const size_t len, const Varray<float> &array, MinMaxSum mms);
template MinMaxSum varrayMinMaxSum(const size_t len, const Varray<double> &array, MinMaxSum mms);
template <typename T>
size_t
varrayMinMaxSumMV(const size_t len, const Varray<T> &array, const T missval, double &rmin, double &rmax, double &rsum)
MinMaxSum
varrayMinMaxSumMV(const size_t len, const Varray<T> &array, const T missval, MinMaxSum mms)
{
// rmin, rmax and rsum will be initialized in Info
T rmin = mms.min;
T rmax = mms.max;
auto rsum = mms.sum;
size_t nvals = 0;
for (size_t i = 0; i < len; ++i)
if (std::isnan(missval))
{
const auto v = array[i];
if (!DBL_IS_EQUAL(v, missval))
for (size_t i = 0; i < len; ++i)
{
if (v < rmin) rmin = v;
if (v > rmax) rmax = v;
rsum += v;
nvals++;
const auto v = array[i];
if (!DBL_IS_EQUAL(v, missval))
{
if (v < rmin) rmin = v;
if (v > rmax) rmax = v;
rsum += v;
nvals++;
}
}
}
else
{
#ifdef HAVE_OPENMP4
#pragma omp simd reduction(min:rmin) reduction(max:rmax) reduction(+:rsum) reduction(+:nvals)
#endif
for (size_t i = 0; i < len; ++i)
{
const auto v = array[i];
if (IS_NOT_EQUAL(v, missval))
{
if (v < rmin) rmin = v;
if (v > rmax) rmax = v;
rsum += v;
nvals++;
}
}
}
if (nvals == 0 && IS_EQUAL(rmin, DBL_MAX)) rmin = missval;
if (nvals == 0 && IS_EQUAL(rmax, -DBL_MAX)) rmax = missval;
return nvals;
return MinMaxSum(rmin, rmax, rsum, nvals);
}
// Explicit instantiation
template size_t varrayMinMaxSumMV(const size_t len, const Varray<float> &array, const float missval, double &rmin, double &rmax, double &rsum);
template size_t varrayMinMaxSumMV(const size_t len, const Varray<double> &array, const double missval, double &rmin, double &rmax, double &rsum);
template MinMaxSum varrayMinMaxSumMV(const size_t len, const Varray<float> &array, const float missval, MinMaxSum mms);
template MinMaxSum varrayMinMaxSumMV(const size_t len, const Varray<double> &array, const double missval, MinMaxSum mms);
void
varrayMinMaxMean(const size_t len, const Varray<double> &array, double &rmin, double &rmax, double &rmean)
......@@ -144,14 +165,12 @@ varrayMinMaxMean(const size_t len, const Varray<double> &array, double &rmin, do
size_t
varrayMinMaxMeanMV(const size_t len, const Varray<double> &array, const double missval, double &rmin, double &rmax, double &rmean)
{
rmin = DBL_MAX;
rmax = -DBL_MAX;
double sum = 0.0;
size_t nvals = varrayMinMaxSumMV(len, array, missval, rmin, rmax, sum);
rmean = nvals ? sum / (double) nvals : missval;
auto mms = varrayMinMaxSumMV(len, array, missval, MinMaxSum());
rmin = mms.min;
rmax = mms.max;
rmean = mms.n ? mms.sum / (double) mms.n : missval;
return nvals;
return mms.n;
}
void
......
......@@ -129,10 +129,10 @@ static inline double FSQRTMN(const double x, const double missval1)
const char *fpe_errstr(int fpeRaised);
template <typename T>
MinMaxSum varrayMinMaxSum(size_t len, const Varray<T> &array, MinMaxSum mmsinit);
MinMaxSum varrayMinMaxSum(size_t len, const Varray<T> &array, MinMaxSum mms);
template <typename T>
size_t varrayMinMaxSumMV(size_t len, const Varray<T> &array, T missval, double &rmin, double &rmax, double &rsum);
MinMaxSum varrayMinMaxSumMV(size_t len, const Varray<T> &array, T missval, MinMaxSum mms);
void varrayMinMaxMean(size_t len, const Varray<double> &array, double &rmin, double &rmax, double &rmean);
size_t varrayMinMaxMeanMV(size_t len, const Varray<double> &array, double missval, double &rmin, double &rmax, double &rmean);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment