Skip to content

Commit 872e488

Browse files
author
Razvan Aguridan
committed
Fix missing value configuration code
1 parent d03d756 commit 872e488

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/multio/action/statistics/StatisticsConfiguration.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,12 @@ void StatisticsConfiguration::readStepFrequency(const message::Message& msg) {
267267

268268
void StatisticsConfiguration::readMissingValue(const message::Message& msg) {
269269
const auto& md = msg.metadata();
270-
auto missingVal = md.getOpt<double>(glossary().missingValue);
271-
std::optional<bool> bitMapPresent;
272-
if (missingVal && (bitMapPresent = md.get<bool>(glossary().bitmapPresent) && *bitMapPresent)) {
273-
haveMissingValue_ = true;
270+
const auto missingVal = md.getOpt<double>(glossary().missingValue);
271+
const auto bitMapPresent = md.getOpt<bool>(glossary().bitmapPresent);
272+
haveMissingValue_ = missingVal && bitMapPresent && *bitMapPresent;
273+
if (haveMissingValue_) {
274274
missingValue_ = *missingVal;
275275
}
276-
return;
277276
};
278277
void StatisticsConfiguration::createLoggingPrefix(const StatisticsConfiguration& cfg, const message::Message& msg) {
279278
std::ostringstream os;
@@ -432,7 +431,7 @@ bool StatisticsConfiguration::solver_send_initial_condition() const {
432431
}
433432

434433
bool StatisticsConfiguration::haveMissingValue() const {
435-
return haveMissingValue_ != 0;
434+
return haveMissingValue_;
436435
};
437436

438437
double StatisticsConfiguration::missingValue() const {

src/multio/action/statistics/operations/Average.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,20 @@ class Average final : public OperationWithData<T> {
4141

4242
private:
4343
void updateWithoutMissing(const T* val) {
44-
const double c2 = icntpp(), c1 = sc(c2);
44+
const T c2 = icntpp(), c1 = sc(c2);
4545
std::transform(values_.begin(), values_.end(), val, values_.begin(),
46-
[c1, c2](T v1, T v2) { return static_cast<T>(v1 * c1 + v2 * c2); });
46+
[c1, c2](T v1, T v2) { return v1 * c1 + v2 * c2; });
4747
return;
4848
}
4949
void updateWithMissing(const T* val) {
50-
const double c2 = icntpp(), c1 = sc(c2), m = cfg_.missingValue();
50+
const T c2 = icntpp(), c1 = sc(c2);
51+
const T m = static_cast<T>(cfg_.missingValue());
5152
std::transform(values_.begin(), values_.end(), val, values_.begin(),
52-
[c1, c2, m](T v1, T v2) { return static_cast<T>(m == v2 ? m : v1 * c1 + v2 * c2); });
53+
[c1, c2, m](T v1, T v2) { return (m == v2) ? m : v1 * c1 + v2 * c2; });
5354
return;
5455
}
55-
double icntpp() const { return double(1.0) / double(win_.count()); };
56-
double sc(double v) const { return double(win_.count() - 1) * v; };
56+
T icntpp() const { return T(1.0) / T(win_.count()); };
57+
T sc(T v) const { return T(win_.count() - 1) * v; };
5758
void print(std::ostream& os) const override { os << logHeader_; }
5859
};
5960

0 commit comments

Comments
 (0)