Skip to content

Commit

Permalink
Merge branch 'release/1.23.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Sep 16, 2024
2 parents 63cce59 + 8e6742b commit c74f6bc
Show file tree
Hide file tree
Showing 31 changed files with 79 additions and 120 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.22.1
1.23.0
20 changes: 10 additions & 10 deletions src/mir/method/MethodWeighted.cc
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,13 @@ void MethodWeighted::setReorderCols(reorder::Reorder* r) {
}


void MethodWeighted::setOperandMatricesFromVectors(WeightMatrix::Matrix& A, WeightMatrix::Matrix& B,
const MIRValuesVector& Avector, const MIRValuesVector& Bvector,
const double& missingValue, const data::Space& space) const {
void MethodWeighted::setOperandMatricesFromVectors(DenseMatrix& A, DenseMatrix& B, const MIRValuesVector& Avector,
const MIRValuesVector& Bvector, const double& missingValue,
const data::Space& space) const {

// set input matrix B (from A = W × B)
// FIXME: remove const_cast once Matrix provides read-only view
WeightMatrix::Matrix Bwrap(const_cast<double*>(Bvector.data()), Bvector.size(), 1);
DenseMatrix Bwrap(const_cast<double*>(Bvector.data()), Bvector.size(), 1);

space.linearise(Bwrap, B, missingValue);

Expand All @@ -374,25 +374,25 @@ void MethodWeighted::setOperandMatricesFromVectors(WeightMatrix::Matrix& A, Weig
if (B.cols() == 1) {

// FIXME: remove const_cast once Matrix provides read-only view
WeightMatrix::Matrix Awrap(const_cast<double*>(Avector.data()), Avector.size(), 1);
DenseMatrix Awrap(const_cast<double*>(Avector.data()), Avector.size(), 1);
A.swap(Awrap);
}
else {

WeightMatrix::Matrix Awrap(Avector.size(), B.cols());
DenseMatrix Awrap(Avector.size(), B.cols());
Awrap.setZero();
A.swap(Awrap);
}
}


void MethodWeighted::setVectorFromOperandMatrix(const WeightMatrix::Matrix& A, MIRValuesVector& Avector,
void MethodWeighted::setVectorFromOperandMatrix(const DenseMatrix& A, MIRValuesVector& Avector,
const double& missingValue, const data::Space& space) const {

// set output vector A (from A = W × B)
// FIXME: remove const_cast once Matrix provides read-only view
ASSERT(Avector.size() == A.rows());
WeightMatrix::Matrix Awrap(const_cast<double*>(Avector.data()), Avector.size(), 1);
DenseMatrix Awrap(const_cast<double*>(Avector.data()), Avector.size(), 1);

space.unlinearise(A, Awrap, missingValue);
}
Expand Down Expand Up @@ -476,8 +476,8 @@ void MethodWeighted::execute(context::Context& ctx, const repres::Representation
const data::Space& sp = data::SpaceChooser::lookup(space);

MIRValuesVector result(npts_out); // field.update() takes ownership with std::swap()
WeightMatrix::Matrix A;
WeightMatrix::Matrix B;
DenseMatrix A;
DenseMatrix B;
setOperandMatricesFromVectors(B, A, result, field.values(i), missingValue, sp);
ASSERT(A.rows() == npts_inp);
ASSERT(B.rows() == npts_out);
Expand Down
18 changes: 10 additions & 8 deletions src/mir/method/MethodWeighted.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <utility>
#include <vector>

#include "eckit/linalg/Matrix.h"

#include "mir/method/Cropping.h"
#include "mir/method/Method.h"
#include "mir/method/WeightMatrix.h"
Expand Down Expand Up @@ -55,13 +57,13 @@ class MIRStatistics;
namespace mir::method {


using DenseMatrix = eckit::linalg::Matrix;


class MethodWeighted : public Method {
public:
// -- Types

using WeightMatrix = method::WeightMatrix;
using Matrix = eckit::linalg::Matrix;

using CacheKeys = std::pair<std::string, std::string>;

// -- Constructors
Expand Down Expand Up @@ -133,13 +135,13 @@ class MethodWeighted : public Method {
WeightMatrix&, const lsm::LandSeaMasks&, const Cropping&) const;

/// Get interpolation operand matrices, from A = W B
virtual void setOperandMatricesFromVectors(WeightMatrix::Matrix& A, WeightMatrix::Matrix& B,
const MIRValuesVector& Avector, const MIRValuesVector& Bvector,
const double& missingValue, const data::Space&) const;
virtual void setOperandMatricesFromVectors(DenseMatrix& A, DenseMatrix& B, const MIRValuesVector& Avector,
const MIRValuesVector& Bvector, const double& missingValue,
const data::Space&) const;

/// Get interpolation operand matrices, from A = W B
virtual void setVectorFromOperandMatrix(const WeightMatrix::Matrix& A, MIRValuesVector& Avector,
const double& missingValue, const data::Space&) const;
virtual void setVectorFromOperandMatrix(const DenseMatrix& A, MIRValuesVector& Avector, const double& missingValue,
const data::Space&) const;

// -- Overridden methods

Expand Down
22 changes: 2 additions & 20 deletions src/mir/method/WeightMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@
#include <iosfwd>
#include <vector>

#include "eckit/linalg/Matrix.h"
#include "eckit/linalg/SparseMatrix.h"


namespace mir::method {


class WeightMatrix : public eckit::linalg::SparseMatrix {

class WeightMatrix final : public eckit::linalg::SparseMatrix {
public: // types
using Triplet = eckit::linalg::Triplet;
using Matrix = eckit::linalg::Matrix;
using Vector = eckit::linalg::Vector;
using Scalar = eckit::linalg::Scalar;
using Size = eckit::linalg::Size;

Expand All @@ -38,26 +34,12 @@ class WeightMatrix : public eckit::linalg::SparseMatrix {

WeightMatrix(Size rows, Size cols);

void setFromTriplets(const std::vector<Triplet>&);
void setFromTriplets(const std::vector<WeightMatrix::Triplet>&);

void cleanup(const double& pruneEpsilon = 0);

void validate(const char* when) const;

using SparseMatrix::cols;
using SparseMatrix::rows;

using SparseMatrix::footprint;
using SparseMatrix::load;
using SparseMatrix::prune;
using SparseMatrix::save;
using SparseMatrix::setIdentity;

using SparseMatrix::begin;
using SparseMatrix::const_iterator;
using SparseMatrix::end;
using SparseMatrix::iterator;

private: // members
void print(std::ostream&) const;

Expand Down
7 changes: 3 additions & 4 deletions src/mir/method/fe/FiniteElement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ static void init() {
namespace {


using triplet_vector_t = std::vector<WeightMatrix::Triplet>;
using element_tree_t = atlas::interpolation::method::ElemIndex3;
using failed_projection_t = std::pair<size_t, PointLatLon>;

Expand All @@ -74,7 +73,7 @@ struct element_t : std::vector<size_t> {

virtual bool intersects(const atlas::interpolation::method::Ray&, double eps) = 0;

void append_triplets(size_t i, size_t nbRealPoints, triplet_vector_t& t) const {
void append_triplets(size_t i, size_t nbRealPoints, std::vector<WeightMatrix::Triplet>& t) const {
ASSERT(size() == weights.size());

bool normalise = std::any_of(cbegin(), cend(), [nbRealPoints](size_t i) { return i >= nbRealPoints; });
Expand Down Expand Up @@ -322,8 +321,8 @@ void FiniteElement::assemble(util::MIRStatistics& statistics, WeightMatrix& W, c
size_t nbFailures = 0;

std::forward_list<failed_projection_t> failures;
triplet_vector_t weights_triplets; // structure to fill-in sparse matrix
weights_triplets.reserve(nbOutputPoints * 4); // preallocate space as if all elements where quads
std::vector<WeightMatrix::Triplet> weights_triplets; // structure to fill-in sparse matrix
weights_triplets.reserve(nbOutputPoints * 4); // preallocate space as if all elements where quads


{
Expand Down
2 changes: 1 addition & 1 deletion src/mir/method/knn/distance/ClimateFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void ClimateFilter::operator()(size_t ip, const Point3& point,
// normalise all weights according to the total, and set sparse matrix triplets
for (size_t j = 0; j < nbPoints; ++j) {
size_t jp = neighbours[j].payload();
triplets.emplace_back(WeightMatrix::Triplet(ip, jp, weights[j] / sum));
triplets.emplace_back(ip, jp, weights[j] / sum);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/mir/method/knn/distance/Cressman.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void Cressman::operator()(size_t ip, const Point3& point,
if (eckit::types::is_strictly_greater(sum, 0.)) {
for (size_t j = 0; j < nbPoints; ++j) {
size_t jp = neighbours[j].payload();
triplets.emplace_back(WeightMatrix::Triplet(ip, jp, weights[j] / sum));
triplets.emplace_back(ip, jp, weights[j] / sum);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/mir/method/nonlinear/Heaviest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace mir::method::nonlinear {
Heaviest::Heaviest(const param::MIRParametrisation& param) : NonLinear(param) {}


bool Heaviest::treatment(MethodWeighted::Matrix& /*A*/, MethodWeighted::WeightMatrix& W, MethodWeighted::Matrix& /*B*/,
const MIRValuesVector& /*unused*/, const double& /*missingValue*/) const {
bool Heaviest::treatment(DenseMatrix& /*A*/, WeightMatrix& W, DenseMatrix& /*B*/, const MIRValuesVector& /*unused*/,
const double& /*missingValue*/) const {

auto* data = const_cast<WeightMatrix::Scalar*>(W.data());

Expand Down
4 changes: 2 additions & 2 deletions src/mir/method/nonlinear/Heaviest.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct Heaviest : NonLinear {
Heaviest(const param::MIRParametrisation&);

private:
bool treatment(MethodWeighted::Matrix& A, MethodWeighted::WeightMatrix& W, MethodWeighted::Matrix& B,
const MIRValuesVector&, const double& missingValue) const override;
bool treatment(DenseMatrix& A, WeightMatrix& W, DenseMatrix& B, const MIRValuesVector&,
const double& missingValue) const override;
bool sameAs(const NonLinear&) const override;
void json(eckit::JSON&) const override;
void print(std::ostream&) const override;
Expand Down
5 changes: 2 additions & 3 deletions src/mir/method/nonlinear/MissingIfAllMissing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ namespace mir::method::nonlinear {
MissingIfAllMissing::MissingIfAllMissing(const param::MIRParametrisation& param) : NonLinear(param) {}


bool MissingIfAllMissing::treatment(MethodWeighted::Matrix& /*A*/, MethodWeighted::WeightMatrix& W,
MethodWeighted::Matrix& /*B*/, const MIRValuesVector& values,
const double& missingValue) const {
bool MissingIfAllMissing::treatment(DenseMatrix& /*A*/, WeightMatrix& W, DenseMatrix& /*B*/,
const MIRValuesVector& values, const double& missingValue) const {

// correct matrix weigths for the missing values
// (force a missing value only if all row values are missing)
Expand Down
4 changes: 2 additions & 2 deletions src/mir/method/nonlinear/MissingIfAllMissing.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct MissingIfAllMissing : NonLinear {
MissingIfAllMissing(const param::MIRParametrisation&);

private:
bool treatment(MethodWeighted::Matrix& A, MethodWeighted::WeightMatrix& W, MethodWeighted::Matrix& B,
const MIRValuesVector&, const double& missingValue) const override;
bool treatment(DenseMatrix& A, WeightMatrix& W, DenseMatrix& B, const MIRValuesVector&,
const double& missingValue) const override;
bool sameAs(const NonLinear&) const override;
void json(eckit::JSON&) const override;
void print(std::ostream&) const override;
Expand Down
5 changes: 2 additions & 3 deletions src/mir/method/nonlinear/MissingIfAnyMissing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ namespace mir::method::nonlinear {
MissingIfAnyMissing::MissingIfAnyMissing(const param::MIRParametrisation& param) : NonLinear(param) {}


bool MissingIfAnyMissing::treatment(MethodWeighted::Matrix& /*A*/, MethodWeighted::WeightMatrix& W,
MethodWeighted::Matrix& /*B*/, const MIRValuesVector& values,
const double& missingValue) const {
bool MissingIfAnyMissing::treatment(DenseMatrix& /*A*/, WeightMatrix& W, DenseMatrix& /*B*/,
const MIRValuesVector& values, const double& missingValue) const {

// correct matrix weigths for the missing values
// (force a missing value only if any row values is missing)
Expand Down
4 changes: 2 additions & 2 deletions src/mir/method/nonlinear/MissingIfAnyMissing.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct MissingIfAnyMissing : NonLinear {
MissingIfAnyMissing(const param::MIRParametrisation&);

private:
bool treatment(MethodWeighted::Matrix& A, MethodWeighted::WeightMatrix& W, MethodWeighted::Matrix& B,
const MIRValuesVector&, const double& missingValue) const override;
bool treatment(DenseMatrix& A, WeightMatrix& W, DenseMatrix& B, const MIRValuesVector&,
const double& missingValue) const override;
bool sameAs(const NonLinear&) const override;
void json(eckit::JSON&) const override;
void print(std::ostream&) const override;
Expand Down
5 changes: 2 additions & 3 deletions src/mir/method/nonlinear/MissingIfHeaviestMissing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ namespace mir::method::nonlinear {
MissingIfHeaviestMissing::MissingIfHeaviestMissing(const param::MIRParametrisation& param) : NonLinear(param) {}


bool MissingIfHeaviestMissing::treatment(MethodWeighted::Matrix& /*A*/, MethodWeighted::WeightMatrix& W,
MethodWeighted::Matrix& /*B*/, const MIRValuesVector& values,
const double& missingValue) const {
bool MissingIfHeaviestMissing::treatment(DenseMatrix& /*A*/, WeightMatrix& W, DenseMatrix& /*B*/,
const MIRValuesVector& values, const double& missingValue) const {

// correct matrix weigths for the missing values
ASSERT(W.cols() == values.size());
Expand Down
4 changes: 2 additions & 2 deletions src/mir/method/nonlinear/MissingIfHeaviestMissing.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct MissingIfHeaviestMissing : NonLinear {
MissingIfHeaviestMissing(const param::MIRParametrisation&);

private:
bool treatment(MethodWeighted::Matrix& A, MethodWeighted::WeightMatrix& W, MethodWeighted::Matrix& B,
const MIRValuesVector&, const double& missingValue) const override;
bool treatment(DenseMatrix& A, WeightMatrix& W, DenseMatrix& B, const MIRValuesVector&,
const double& missingValue) const override;
bool sameAs(const NonLinear&) const override;
void json(eckit::JSON&) const override;
void print(std::ostream&) const override;
Expand Down
5 changes: 2 additions & 3 deletions src/mir/method/nonlinear/NoNonLinear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ namespace mir::method::nonlinear {
NoNonLinear::NoNonLinear(const param::MIRParametrisation& param) : NonLinear(param) {}


bool NoNonLinear::treatment(MethodWeighted::Matrix& /*A*/, MethodWeighted::WeightMatrix& /*W*/,
MethodWeighted::Matrix& /*B*/, const MIRValuesVector& /*unused*/,
const double& /*missingValue*/) const {
bool NoNonLinear::treatment(DenseMatrix& /*A*/, WeightMatrix& /*W*/, DenseMatrix& /*B*/,
const MIRValuesVector& /*unused*/, const double& /*missingValue*/) const {
// no non-linear treatment
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mir/method/nonlinear/NoNonLinear.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ struct NoNonLinear : NonLinear {
NoNonLinear(const param::MIRParametrisation&);

private:
bool treatment(MethodWeighted::Matrix& A, MethodWeighted::WeightMatrix& W, MethodWeighted::Matrix& B,
const MIRValuesVector&, const double& missingValue) const override;
bool treatment(DenseMatrix& A, WeightMatrix& W, DenseMatrix& B, const MIRValuesVector&,
const double& missingValue) const override;
bool sameAs(const NonLinear&) const override;
void json(eckit::JSON&) const override;
void print(std::ostream&) const override;
Expand Down
36 changes: 11 additions & 25 deletions src/mir/method/nonlinear/NonLinear.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@
#include "mir/method/MethodWeighted.h"


namespace eckit {
class JSON;
class MD5;
namespace linalg {
class Matrix;
}
} // namespace eckit

namespace mir {
namespace method {
class WeightMatrix;
}
namespace param {
class MIRParametrisation;
}
} // namespace mir


namespace mir::method::nonlinear {


Expand All @@ -44,13 +26,15 @@ class NonLinear {
explicit NonLinear(const param::MIRParametrisation&);

NonLinear(const NonLinear&) = delete;
NonLinear(NonLinear&&) = delete;
void operator=(NonLinear&&) = delete;
void operator=(const NonLinear&) = delete;

virtual ~NonLinear();

/// Update interpolation linear system to account for non-linearities
virtual bool treatment(MethodWeighted::Matrix& A, MethodWeighted::WeightMatrix& W, MethodWeighted::Matrix& B,
const MIRValuesVector&, const double& missingValue) const = 0;
virtual bool treatment(DenseMatrix& A, WeightMatrix& W, DenseMatrix& B, const MIRValuesVector&,
const double& missingValue) const = 0;

virtual bool sameAs(const NonLinear&) const = 0;
virtual void hash(eckit::MD5&) const = 0;
Expand Down Expand Up @@ -78,14 +62,16 @@ class NonLinearFactory {
std::string name_;
virtual NonLinear* make(const param::MIRParametrisation&) = 0;

NonLinearFactory(const NonLinearFactory&) = delete;
NonLinearFactory& operator=(const NonLinearFactory&) = delete;

protected:
NonLinearFactory(const std::string& name);
explicit NonLinearFactory(const std::string& name);
virtual ~NonLinearFactory();

public:
NonLinearFactory(const NonLinearFactory&) = delete;
NonLinearFactory(NonLinearFactory&&) = delete;
NonLinearFactory& operator=(NonLinearFactory&&) = delete;
NonLinearFactory& operator=(const NonLinearFactory&) = delete;

static const NonLinear* build(const std::string& name, const param::MIRParametrisation&);
static void list(std::ostream&);
};
Expand All @@ -96,7 +82,7 @@ class NonLinearBuilder : public NonLinearFactory {
NonLinear* make(const param::MIRParametrisation& param) override { return new T(param); }

public:
NonLinearBuilder(const std::string& name) : NonLinearFactory(name) {}
explicit NonLinearBuilder(const std::string& name) : NonLinearFactory(name) {}
};


Expand Down
Loading

0 comments on commit c74f6bc

Please sign in to comment.