Skip to content

Commit

Permalink
Fix missing value configuration code
Browse files Browse the repository at this point in the history
  • Loading branch information
Razvan Aguridan committed Aug 4, 2024
1 parent d03d756 commit 872e488
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 5 additions & 6 deletions src/multio/action/statistics/StatisticsConfiguration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,12 @@ void StatisticsConfiguration::readStepFrequency(const message::Message& msg) {

void StatisticsConfiguration::readMissingValue(const message::Message& msg) {
const auto& md = msg.metadata();
auto missingVal = md.getOpt<double>(glossary().missingValue);
std::optional<bool> bitMapPresent;
if (missingVal && (bitMapPresent = md.get<bool>(glossary().bitmapPresent) && *bitMapPresent)) {
haveMissingValue_ = true;
const auto missingVal = md.getOpt<double>(glossary().missingValue);
const auto bitMapPresent = md.getOpt<bool>(glossary().bitmapPresent);
haveMissingValue_ = missingVal && bitMapPresent && *bitMapPresent;
if (haveMissingValue_) {
missingValue_ = *missingVal;
}
return;
};
void StatisticsConfiguration::createLoggingPrefix(const StatisticsConfiguration& cfg, const message::Message& msg) {
std::ostringstream os;
Expand Down Expand Up @@ -432,7 +431,7 @@ bool StatisticsConfiguration::solver_send_initial_condition() const {
}

bool StatisticsConfiguration::haveMissingValue() const {
return haveMissingValue_ != 0;
return haveMissingValue_;
};

double StatisticsConfiguration::missingValue() const {
Expand Down
13 changes: 7 additions & 6 deletions src/multio/action/statistics/operations/Average.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,20 @@ class Average final : public OperationWithData<T> {

private:
void updateWithoutMissing(const T* val) {
const double c2 = icntpp(), c1 = sc(c2);
const T c2 = icntpp(), c1 = sc(c2);
std::transform(values_.begin(), values_.end(), val, values_.begin(),
[c1, c2](T v1, T v2) { return static_cast<T>(v1 * c1 + v2 * c2); });
[c1, c2](T v1, T v2) { return v1 * c1 + v2 * c2; });
return;
}
void updateWithMissing(const T* val) {
const double c2 = icntpp(), c1 = sc(c2), m = cfg_.missingValue();
const T c2 = icntpp(), c1 = sc(c2);
const T m = static_cast<T>(cfg_.missingValue());
std::transform(values_.begin(), values_.end(), val, values_.begin(),
[c1, c2, m](T v1, T v2) { return static_cast<T>(m == v2 ? m : v1 * c1 + v2 * c2); });
[c1, c2, m](T v1, T v2) { return (m == v2) ? m : v1 * c1 + v2 * c2; });
return;
}
double icntpp() const { return double(1.0) / double(win_.count()); };
double sc(double v) const { return double(win_.count() - 1) * v; };
T icntpp() const { return T(1.0) / T(win_.count()); };
T sc(T v) const { return T(win_.count() - 1) * v; };
void print(std::ostream& os) const override { os << logHeader_; }
};

Expand Down

0 comments on commit 872e488

Please sign in to comment.