From a040c317c614438b72f02fe84c48f12cca87a4e5 Mon Sep 17 00:00:00 2001 From: Carlos Pena De Pedro Date: Mon, 4 Nov 2024 19:27:58 +0100 Subject: [PATCH 1/5] Added bitmask option --- src/mir/method/MethodWeighted.cc | 102 ++++++++++++++++++++++++- src/mir/method/MethodWeighted.h | 1 + src/mir/param/MIRParametrisation.cc | 13 ++++ src/mir/param/MIRParametrisation.h | 1 + src/mir/param/SimpleParametrisation.cc | 35 +++++++++ src/mir/param/SimpleParametrisation.h | 2 + 6 files changed, 151 insertions(+), 3 deletions(-) diff --git a/src/mir/method/MethodWeighted.cc b/src/mir/method/MethodWeighted.cc index 028420524..965c1658b 100644 --- a/src/mir/method/MethodWeighted.cc +++ b/src/mir/method/MethodWeighted.cc @@ -173,6 +173,17 @@ void MethodWeighted::createMatrix(context::Context& ctx, const repres::Represent W.validate("applyMasks"); } } + + bool bitmask; + parametrisation_.get("imm", bitmask); + if (bitmask){ + std::vector vec_bitmask; + applyIMM(W,vec_bitmask); + if (matrixValidate_) { + W.validate("applyMasks"); + } + } + } @@ -207,6 +218,13 @@ MethodWeighted::CacheKeys MethodWeighted::getDiskAndMemoryCacheKeys(const repres } } + bool bitmask; + parametrisation_.get("imm", bitmask); + if (bitmask){ + std::string missing_mask_key; + parametrisation_.get("imm-name", missing_mask_key); + memory_key += "_" + missing_mask_key; + } return {disk_key, memory_key}; } @@ -451,12 +469,16 @@ void MethodWeighted::execute(context::Context& ctx, const repres::Representation const double missingValue = field.missingValue(); // matrix copy: run-time modifiable matrix is not cacheable - const bool matrixCopy = std::any_of(nonLinear_.begin(), nonLinear_.end(), + bool imm_active; + parametrisation_.get("imm", imm_active); + bool matrixCopy = false; + if (!imm_active) { + matrixCopy = std::any_of(nonLinear_.begin(), nonLinear_.end(), [&field](const std::unique_ptr& n) { return n->modifiesMatrix(field.hasMissing()); }); - - + } + for (size_t i = 0; i < field.dimensions(); i++) { std::ostringstream os; @@ -629,6 +651,80 @@ void MethodWeighted::applyMasks(WeightMatrix& W, const lsm::LandSeaMasks& masks) << Log::Pretty(W.rows(), {"output point"}) << std::endl; } +void MethodWeighted::applyIMM(WeightMatrix& W, std::vector imask) const { + trace::Timer timer("MethodWeighted::applyIMM"); + auto& log = Log::debug(); + + log << "MethodWeighted::applyIMM" << std::endl; + + log << "mask size=" << imask.size() << " == #cols=" << W.cols() << std::endl; + + ASSERT(imask.size() == W.cols()); + + auto* data = const_cast(W.data()); + WeightMatrix::Size i = 0; + WeightMatrix::iterator it(W); + size_t fix = 0; + + for (WeightMatrix::Size r = 0; r < W.rows(); ++r) { + + const WeightMatrix::iterator end = W.end(r); + + // count missing values, accumulate weights (disregarding missing values) and find maximum weight in row + size_t i_missing = i; + size_t N_missing = 0; + size_t N_entries = 0; + double sum = 0.; + double heaviest = -1.; + bool heaviest_is_missing = false; + + WeightMatrix::iterator kt(it); + WeightMatrix::Size k = i; + for (; it != end; ++it, ++i, ++N_entries) { + + const bool miss = imask[it.col()]==0.; + + if (miss) { + + ++N_missing; + i_missing = i; + } + else { + sum += *it; + } + + if (heaviest < data[i]) { + heaviest = data[i]; + heaviest_is_missing = miss; + } + } + + // weights redistribution: zero-weight all missing values, linear re-weighting for the others; + // if all values are missing, or the closest value is missing, force missing value + if (N_missing > 0) { + fix++; + if (N_missing == N_entries || heaviest_is_missing || eckit::types::is_approximately_equal(sum, 0.)) { + + for (WeightMatrix::Size j = k; j < k + N_entries; ++j) { + data[j] = j == i_missing ? 1. : 0.; + } + } + else { + + const double factor = 1. / sum; + for (WeightMatrix::Size j = k; j < k + N_entries; ++j, ++kt) { + const bool miss = imask[kt.col()]==0.; + data[j] = miss ? 0. : (factor * data[j]); + } + } + + } + } + + // log corrections + log << "MethodWeighted: applyIMM corrected " << Log::Pretty(fix) << " out of " + << Log::Pretty(W.rows(), {"Weight matrix rows"}) << std::endl; +} void MethodWeighted::hash(eckit::MD5& md5) const { md5.add(name()); diff --git a/src/mir/method/MethodWeighted.h b/src/mir/method/MethodWeighted.h index bf1e6ec9e..6d6bd697b 100644 --- a/src/mir/method/MethodWeighted.h +++ b/src/mir/method/MethodWeighted.h @@ -124,6 +124,7 @@ class MethodWeighted : public Method { const lsm::LandSeaMasks&) const; virtual void applyMasks(WeightMatrix&, const lsm::LandSeaMasks&) const; + virtual void applyIMM(WeightMatrix&, const std::vector) const; virtual lsm::LandSeaMasks getMasks(const repres::Representation& in, const repres::Representation& out) const; virtual bool validateMatrixWeights() const; diff --git a/src/mir/param/MIRParametrisation.cc b/src/mir/param/MIRParametrisation.cc index 882088a72..190416849 100644 --- a/src/mir/param/MIRParametrisation.cc +++ b/src/mir/param/MIRParametrisation.cc @@ -89,4 +89,17 @@ bool MIRParametrisation::get(const std::string& name, std::vector& va return false; } +bool MIRParametrisation::get(const std::string& name, std::vector& value) const { + std::vector v; // Intermediate vector + if (get(name, v)) { // Attempt to retrieve as std::vector + value.clear(); + value.reserve(v.size()); + for (const int& i : v) { + value.push_back(i != 0); // Convert each int to bool (0 -> false, non-zero -> true) + } + return true; + } + return false; +} + } // namespace mir::param diff --git a/src/mir/param/MIRParametrisation.h b/src/mir/param/MIRParametrisation.h index ad8efc61d..ccc2d3c10 100644 --- a/src/mir/param/MIRParametrisation.h +++ b/src/mir/param/MIRParametrisation.h @@ -63,6 +63,7 @@ class MIRParametrisation : public eckit::Parametrisation { bool get(const std::string& name, std::vector& value) const override = 0; bool get(const std::string& name, std::vector& value) const override = 0; bool get(const std::string& name, std::vector& value) const override = 0; + bool get(const std::string& name, std::vector& value) const; bool get(const std::string& name, size_t& value) const override; bool get(const std::string& name, std::vector& value) const override; diff --git a/src/mir/param/SimpleParametrisation.cc b/src/mir/param/SimpleParametrisation.cc index 57177b3da..9471f9820 100644 --- a/src/mir/param/SimpleParametrisation.cc +++ b/src/mir/param/SimpleParametrisation.cc @@ -158,6 +158,12 @@ const char* TNamed>() { return "vector"; } +template <> +const char* TNamed>() { + return "vector"; +} + + template static void conversion_warning(const char* /*from*/, const char* /*to*/, const std::string& /*name*/, @@ -226,6 +232,10 @@ class TSettings : public Setting { throw exception::CannotConvert(TNamed(), "vector", name, value_); } + void get(const std::string& name, std::vector& /*value*/) const { + throw exception::CannotConvert(TNamed(), "vector", name, value_); + } + bool matchAll(const std::string& name, const MIRParametrisation& other) const override { T value; return other.get(name, value) && value_ == value; @@ -269,6 +279,11 @@ void TSettings>::print(std::ostream& out) const { _put(out, value_); } +template <> +void TSettings>::print(std::ostream& out) const { + _put(out, value_); // Uses the `_put` helper function for formatting +} + template <> bool TSettings>::matchAll(const std::string& name, const MIRParametrisation& other) const { @@ -443,6 +458,10 @@ void TSettings>::get(const std::string& /*name*/, std::vecto value = value_; } +template <> +void TSettings>::get(const std::string& /*name*/, std::vector& value) const { + value = value_; +} template <> void TSettings::get(const std::string& name, std::string& value) const { @@ -555,6 +574,18 @@ void TSettings>::get(const std::string& name, std::stri } } +template <> +void TSettings>::get(const std::string& name, std::string& value) const { + conversion_warning("vector", "string", name, value_); + value.clear(); + + const char* sep = ""; + for (const auto& entry : value_) { + value += sep + std::to_string(entry); + sep = "/"; + } +} + SimpleParametrisation::SimpleParametrisation() = default; @@ -779,6 +810,10 @@ SimpleParametrisation& SimpleParametrisation::set(const std::string& name, const _set(name, value); return *this; } +SimpleParametrisation& SimpleParametrisation::set(const std::string& name, const std::vector& value) { + _set(name, value); + return *this; +} void SimpleParametrisation::print(std::ostream& out) const { diff --git a/src/mir/param/SimpleParametrisation.h b/src/mir/param/SimpleParametrisation.h index a4548a6a7..f61db87c3 100644 --- a/src/mir/param/SimpleParametrisation.h +++ b/src/mir/param/SimpleParametrisation.h @@ -66,6 +66,7 @@ class SimpleParametrisation : public MIRParametrisation { SimpleParametrisation& set(const std::string& name, const std::vector& value); SimpleParametrisation& set(const std::string& name, const std::vector& value); SimpleParametrisation& set(const std::string& name, const std::vector& value); + SimpleParametrisation& set(const std::string& name, const std::vector& value); SimpleParametrisation& set(const std::string& name, const std::vector& value); SimpleParametrisation& set(const std::string& name, const std::vector& value); SimpleParametrisation& set(const std::string& name, const std::vector& value); @@ -95,6 +96,7 @@ class SimpleParametrisation : public MIRParametrisation { bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; + bool get(const std::string& name, std::vector& value) const; bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; From dcb04304bcbe5e42831f10bbec1827e391dd24d0 Mon Sep 17 00:00:00 2001 From: Carlos Pena De Pedro Date: Fri, 8 Nov 2024 15:39:39 +0100 Subject: [PATCH 2/5] Completed and fixed this implementation --- src/mir/method/MethodWeighted.cc | 3 ++- src/mir/param/CombinedParametrisation.cc | 4 ++++ src/mir/param/CombinedParametrisation.h | 1 + src/mir/param/MIRParametrisation.cc | 15 ++++----------- src/mir/param/MIRParametrisation.h | 2 +- src/mir/param/SimpleParametrisation.cc | 4 ++++ src/mir/param/SimpleParametrisation.h | 2 +- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/mir/method/MethodWeighted.cc b/src/mir/method/MethodWeighted.cc index 965c1658b..b4a3a96a9 100644 --- a/src/mir/method/MethodWeighted.cc +++ b/src/mir/method/MethodWeighted.cc @@ -178,7 +178,8 @@ void MethodWeighted::createMatrix(context::Context& ctx, const repres::Represent parametrisation_.get("imm", bitmask); if (bitmask){ std::vector vec_bitmask; - applyIMM(W,vec_bitmask); + parametrisation_.get("imm-mask", vec_bitmask); + applyIMM(W,vec_bitmask); if (matrixValidate_) { W.validate("applyMasks"); } diff --git a/src/mir/param/CombinedParametrisation.cc b/src/mir/param/CombinedParametrisation.cc index 4635e5a9f..653e27681 100644 --- a/src/mir/param/CombinedParametrisation.cc +++ b/src/mir/param/CombinedParametrisation.cc @@ -108,6 +108,10 @@ bool CombinedParametrisation::get(const std::string& name, std::vector& return _get(name, value); } +bool CombinedParametrisation::get(const std::string& name, std::vector& value) const { + return _get(name, value); +} + bool CombinedParametrisation::get(const std::string& name, std::vector& value) const { return _get(name, value); } diff --git a/src/mir/param/CombinedParametrisation.h b/src/mir/param/CombinedParametrisation.h index 884ec8fc6..13960181e 100644 --- a/src/mir/param/CombinedParametrisation.h +++ b/src/mir/param/CombinedParametrisation.h @@ -100,6 +100,7 @@ class CombinedParametrisation : public MIRParametrisation { bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; + bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; // -- Class members diff --git a/src/mir/param/MIRParametrisation.cc b/src/mir/param/MIRParametrisation.cc index 190416849..e85c6e27c 100644 --- a/src/mir/param/MIRParametrisation.cc +++ b/src/mir/param/MIRParametrisation.cc @@ -90,16 +90,9 @@ bool MIRParametrisation::get(const std::string& name, std::vector& va } bool MIRParametrisation::get(const std::string& name, std::vector& value) const { - std::vector v; // Intermediate vector - if (get(name, v)) { // Attempt to retrieve as std::vector - value.clear(); - value.reserve(v.size()); - for (const int& i : v) { - value.push_back(i != 0); // Convert each int to bool (0 -> false, non-zero -> true) - } - return true; - } - return false; -} + std::ostringstream os; + os << "MIRParametrisation::get(const std::string& name, std::vector& value) not implemented for " << *this; + throw exception::SeriousBug(os.str()); + } } // namespace mir::param diff --git a/src/mir/param/MIRParametrisation.h b/src/mir/param/MIRParametrisation.h index ccc2d3c10..b2d52efea 100644 --- a/src/mir/param/MIRParametrisation.h +++ b/src/mir/param/MIRParametrisation.h @@ -63,7 +63,7 @@ class MIRParametrisation : public eckit::Parametrisation { bool get(const std::string& name, std::vector& value) const override = 0; bool get(const std::string& name, std::vector& value) const override = 0; bool get(const std::string& name, std::vector& value) const override = 0; - bool get(const std::string& name, std::vector& value) const; + virtual bool get(const std::string& name, std::vector& value) const ; bool get(const std::string& name, size_t& value) const override; bool get(const std::string& name, std::vector& value) const override; diff --git a/src/mir/param/SimpleParametrisation.cc b/src/mir/param/SimpleParametrisation.cc index 9471f9820..839f03171 100644 --- a/src/mir/param/SimpleParametrisation.cc +++ b/src/mir/param/SimpleParametrisation.cc @@ -54,6 +54,7 @@ class Setting { virtual void get(const std::string& name, std::vector& value) const = 0; virtual void get(const std::string& name, std::vector& value) const = 0; virtual void get(const std::string& name, std::vector& value) const = 0; + virtual void get(const std::string& name, std::vector& value) const = 0; virtual bool matchAll(const std::string& name, const MIRParametrisation&) const = 0; virtual bool matchAny(const std::string& name, const MIRParametrisation&) const = 0; @@ -673,6 +674,9 @@ bool SimpleParametrisation::get(const std::string& name, std::vector& va return _get(name, value); } +bool SimpleParametrisation::get(const std::string& name, std::vector& value) const { + return _get(name, value); +} bool SimpleParametrisation::get(const std::string& /*name*/, std::vector& /*value*/) const { NOTIMP; diff --git a/src/mir/param/SimpleParametrisation.h b/src/mir/param/SimpleParametrisation.h index f61db87c3..98d509a0b 100644 --- a/src/mir/param/SimpleParametrisation.h +++ b/src/mir/param/SimpleParametrisation.h @@ -96,7 +96,7 @@ class SimpleParametrisation : public MIRParametrisation { bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; - bool get(const std::string& name, std::vector& value) const; + bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; bool get(const std::string& name, std::vector& value) const override; From 9ff1663fb5da4986bc360d598fda811f95a95efc Mon Sep 17 00:00:00 2001 From: Carlos Date: Fri, 15 Nov 2024 13:26:12 +0100 Subject: [PATCH 3/5] Sparse Matrix access improved --- src/mir/method/MethodWeighted.cc | 123 +++++++++++++++---------------- 1 file changed, 58 insertions(+), 65 deletions(-) diff --git a/src/mir/method/MethodWeighted.cc b/src/mir/method/MethodWeighted.cc index b4a3a96a9..e78f9297c 100644 --- a/src/mir/method/MethodWeighted.cc +++ b/src/mir/method/MethodWeighted.cc @@ -653,80 +653,73 @@ void MethodWeighted::applyMasks(WeightMatrix& W, const lsm::LandSeaMasks& masks) } void MethodWeighted::applyIMM(WeightMatrix& W, std::vector imask) const { - trace::Timer timer("MethodWeighted::applyIMM"); - auto& log = Log::debug(); - - log << "MethodWeighted::applyIMM" << std::endl; - - log << "mask size=" << imask.size() << " == #cols=" << W.cols() << std::endl; - - ASSERT(imask.size() == W.cols()); - - auto* data = const_cast(W.data()); - WeightMatrix::Size i = 0; - WeightMatrix::iterator it(W); - size_t fix = 0; - - for (WeightMatrix::Size r = 0; r < W.rows(); ++r) { - - const WeightMatrix::iterator end = W.end(r); - - // count missing values, accumulate weights (disregarding missing values) and find maximum weight in row - size_t i_missing = i; - size_t N_missing = 0; - size_t N_entries = 0; - double sum = 0.; - double heaviest = -1.; - bool heaviest_is_missing = false; - - WeightMatrix::iterator kt(it); - WeightMatrix::Size k = i; - for (; it != end; ++it, ++i, ++N_entries) { - - const bool miss = imask[it.col()]==0.; - - if (miss) { - - ++N_missing; - i_missing = i; - } - else { - sum += *it; - } - - if (heaviest < data[i]) { - heaviest = data[i]; - heaviest_is_missing = miss; - } + trace::Timer timer("MethodWeighted::applyIMM"); +auto& log = Log::debug(); + +log << "MethodWeighted::applyIMM" << std::endl; +log << "mask size=" << imask.size() << " == #cols=" << W.cols() << std::endl; + +// Ensure that the mask size matches the number of columns in W +ASSERT(imask.size() == W.cols()); + +auto* data = const_cast(W.data()); +auto* outer = W.outer(); +auto* inner = W.inner(); +size_t fix = 0; + +// Iterate over each row +for (WeightMatrix::Size r = 0; r < W.rows(); ++r) { + WeightMatrix::Size row_start = outer[r]; + WeightMatrix::Size row_end = outer[r + 1]; + + size_t i_missing = row_start; + size_t N_missing = 0; + size_t N_entries = row_end - row_start; + double sum = 0.0; + double heaviest = -1.0; + bool heaviest_is_missing = false; + + // Iterate over the entries in the current row + for (WeightMatrix::Size i = row_start; i < row_end; ++i) { + const bool miss = imask[inner[i]] == 0.0; + + if (miss) { + ++N_missing; + i_missing = i; + } else { + sum += data[i]; } - // weights redistribution: zero-weight all missing values, linear re-weighting for the others; - // if all values are missing, or the closest value is missing, force missing value - if (N_missing > 0) { - fix++; - if (N_missing == N_entries || heaviest_is_missing || eckit::types::is_approximately_equal(sum, 0.)) { + if (heaviest < data[i]) { + heaviest = data[i]; + heaviest_is_missing = miss; + } + } - for (WeightMatrix::Size j = k; j < k + N_entries; ++j) { - data[j] = j == i_missing ? 1. : 0.; - } + // Weights redistribution: zero-weight all missing values, linear re-weighting for the others + if (N_missing > 0) { + ++fix; + if (N_missing == N_entries || heaviest_is_missing || eckit::types::is_approximately_equal(sum, 0.0)) { + // All values are missing or the heaviest is missing; set only i_missing to 1 + for (WeightMatrix::Size i = row_start; i < row_end; ++i) { + data[i] = (i == i_missing) ? 1.0 : 0.0; } - else { - - const double factor = 1. / sum; - for (WeightMatrix::Size j = k; j < k + N_entries; ++j, ++kt) { - const bool miss = imask[kt.col()]==0.; - data[j] = miss ? 0. : (factor * data[j]); - } + } else { + // Scale non-missing entries so they sum to 1 + const double factor = 1.0 / sum; + for (WeightMatrix::Size i = row_start; i < row_end; ++i) { + const bool miss = imask[inner[i]] == 0.0; + data[i] = miss ? 0.0 : (factor * data[i]); } - } } - - // log corrections - log << "MethodWeighted: applyIMM corrected " << Log::Pretty(fix) << " out of " - << Log::Pretty(W.rows(), {"Weight matrix rows"}) << std::endl; } +// Log the number of corrections made +log << "MethodWeighted: applyIMM corrected " << Log::Pretty(fix) << " out of " + << Log::Pretty(W.rows(), {"Weight matrix rows"}) << std::endl; +} + void MethodWeighted::hash(eckit::MD5& md5) const { md5.add(name()); md5 << pruneEpsilon_; From 1ea9c33494724b06c7889a5703001608b155739b Mon Sep 17 00:00:00 2001 From: Carlos Pena De Pedro Date: Wed, 20 Nov 2024 13:47:12 +0100 Subject: [PATCH 4/5] Added IMM mask default to false --- src/mir/param/DefaultParametrisation.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mir/param/DefaultParametrisation.cc b/src/mir/param/DefaultParametrisation.cc index 8d76e4693..20d91cb1e 100644 --- a/src/mir/param/DefaultParametrisation.cc +++ b/src/mir/param/DefaultParametrisation.cc @@ -37,6 +37,9 @@ DefaultParametrisation::DefaultParametrisation() { set("lsm-weight-adjustment", 0.2); set("lsm-value-threshold", 0.5); + set("imm", false); + + set("spectral-order", "linear"); set("compare", "scalar"); From 79b06babe6b6d606d0a92db4535b8eecfc02c669 Mon Sep 17 00:00:00 2001 From: Carlos Date: Wed, 20 Nov 2024 14:07:46 +0100 Subject: [PATCH 5/5] Tidy up and some fixes --- src/mir/method/MethodWeighted.cc | 9 +++++---- src/mir/method/MethodWeighted.h | 2 +- src/mir/param/DefaultParametrisation.cc | 3 ++- src/mir/param/MIRParametrisation.cc | 1 - 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/mir/method/MethodWeighted.cc b/src/mir/method/MethodWeighted.cc index e78f9297c..6174b8b94 100644 --- a/src/mir/method/MethodWeighted.cc +++ b/src/mir/method/MethodWeighted.cc @@ -178,7 +178,7 @@ void MethodWeighted::createMatrix(context::Context& ctx, const repres::Represent parametrisation_.get("imm", bitmask); if (bitmask){ std::vector vec_bitmask; - parametrisation_.get("imm-mask", vec_bitmask); + parametrisation_.get("imm-mask", vec_bitmask); applyIMM(W,vec_bitmask); if (matrixValidate_) { W.validate("applyMasks"); @@ -225,6 +225,7 @@ MethodWeighted::CacheKeys MethodWeighted::getDiskAndMemoryCacheKeys(const repres std::string missing_mask_key; parametrisation_.get("imm-name", missing_mask_key); memory_key += "_" + missing_mask_key; + disk_key += "_" + missing_mask_key; } return {disk_key, memory_key}; } @@ -652,7 +653,7 @@ void MethodWeighted::applyMasks(WeightMatrix& W, const lsm::LandSeaMasks& masks) << Log::Pretty(W.rows(), {"output point"}) << std::endl; } -void MethodWeighted::applyIMM(WeightMatrix& W, std::vector imask) const { +void MethodWeighted::applyIMM(WeightMatrix& W, const std::vector& imask) const { trace::Timer timer("MethodWeighted::applyIMM"); auto& log = Log::debug(); @@ -681,7 +682,7 @@ for (WeightMatrix::Size r = 0; r < W.rows(); ++r) { // Iterate over the entries in the current row for (WeightMatrix::Size i = row_start; i < row_end; ++i) { - const bool miss = imask[inner[i]] == 0.0; + const bool miss = !imask[inner[i]]; if (miss) { ++N_missing; @@ -708,7 +709,7 @@ for (WeightMatrix::Size r = 0; r < W.rows(); ++r) { // Scale non-missing entries so they sum to 1 const double factor = 1.0 / sum; for (WeightMatrix::Size i = row_start; i < row_end; ++i) { - const bool miss = imask[inner[i]] == 0.0; + const bool miss = !imask[inner[i]]; data[i] = miss ? 0.0 : (factor * data[i]); } } diff --git a/src/mir/method/MethodWeighted.h b/src/mir/method/MethodWeighted.h index 6d6bd697b..4096782eb 100644 --- a/src/mir/method/MethodWeighted.h +++ b/src/mir/method/MethodWeighted.h @@ -124,7 +124,7 @@ class MethodWeighted : public Method { const lsm::LandSeaMasks&) const; virtual void applyMasks(WeightMatrix&, const lsm::LandSeaMasks&) const; - virtual void applyIMM(WeightMatrix&, const std::vector) const; + virtual void applyIMM(WeightMatrix&, const std::vector&) const; virtual lsm::LandSeaMasks getMasks(const repres::Representation& in, const repres::Representation& out) const; virtual bool validateMatrixWeights() const; diff --git a/src/mir/param/DefaultParametrisation.cc b/src/mir/param/DefaultParametrisation.cc index 20d91cb1e..bc0d414eb 100644 --- a/src/mir/param/DefaultParametrisation.cc +++ b/src/mir/param/DefaultParametrisation.cc @@ -38,7 +38,8 @@ DefaultParametrisation::DefaultParametrisation() { set("lsm-value-threshold", 0.5); set("imm", false); - + set("imm-name", "bitmasked"); + set("imm-mask", std::vector{}); set("spectral-order", "linear"); diff --git a/src/mir/param/MIRParametrisation.cc b/src/mir/param/MIRParametrisation.cc index e85c6e27c..566ec8efc 100644 --- a/src/mir/param/MIRParametrisation.cc +++ b/src/mir/param/MIRParametrisation.cc @@ -93,6 +93,5 @@ bool MIRParametrisation::get(const std::string& name, std::vector& value) std::ostringstream os; os << "MIRParametrisation::get(const std::string& name, std::vector& value) not implemented for " << *this; throw exception::SeriousBug(os.str()); - } } // namespace mir::param