From d2eb4f8a3c773ff4e340fb3f41eee66a988ab9a7 Mon Sep 17 00:00:00 2001 From: Pierre Marchand Date: Fri, 9 Aug 2024 19:29:08 +0200 Subject: [PATCH] improve coverage --- .../solver/geneo/coarse_space_builder.hpp | 141 ------------------ .../geneo/coarse_space_dense_builder.hpp | 16 +- src/htool/solver/solver.hpp | 6 - 3 files changed, 8 insertions(+), 155 deletions(-) delete mode 100644 src/htool/solver/geneo/coarse_space_builder.hpp diff --git a/src/htool/solver/geneo/coarse_space_builder.hpp b/src/htool/solver/geneo/coarse_space_builder.hpp deleted file mode 100644 index b829276..0000000 --- a/src/htool/solver/geneo/coarse_space_builder.hpp +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef HTOOL_PYTHON_GENEO_COARSE_SPACE_BUILDER_HPP -#define HTOOL_PYTHON_GENEO_COARSE_SPACE_BUILDER_HPP - -#include -#include -#include -namespace py = pybind11; - -template -class GeneoCoarseSpaceBuilderPython : public VirtualCoarseSpaceBuilder { - py::array_t m_coarse_space; - - int m_size_wo_overlap; - int m_size_with_overlap; - Matrix m_DAiD; - Matrix m_Bi; - char m_symmetry = 'N'; - char m_uplo = 'N'; - int m_geneo_nu = 2; - htool::underlying_type m_geneo_threshold = -1.; - - // using GeneoCoarseSpaceDenseBuilder::GeneoCoarseSpaceDenseBuilder; - public: - char get_symmetry() { return this->m_symmetry; } - int get_geneo_nu() { return this->m_geneo_nu; } - htool::underlying_type get_geneo_threshold() { return this->m_geneo_threshold; } - - explicit GeneoCoarseSpaceBuilderPython(int size_wo_overlap, HMatrix Ai, Matrix Bi, char symmetry, char uplo, int geneo_nu, htool::underlying_type geneo_threshold) : m_size_wo_overlap(size_wo_overlap), m_size_with_overlap(Ai.nb_cols()), m_DAiD(m_size_with_overlap, m_size_with_overlap), m_Bi(Bi), m_symmetry(symmetry), m_uplo(uplo), m_geneo_nu(geneo_nu), m_geneo_threshold(geneo_threshold) {} - - Matrix build_coarse_space() override { - py::array_t Ai(std::array{this->m_DAiD.nb_rows(), this->m_DAiD.nb_cols()}, this->m_DAiD.data(), py::capsule(this->m_DAiD.data())); - py::array_t Bi(std::array{this->m_Bi.nb_rows(), this->m_Bi.nb_cols()}, this->m_Bi.data(), py::capsule(this->m_Bi.data())); - compute_coarse_space(Ai, Bi); - Matrix coarse_space_mat(m_coarse_space.shape()[0], m_coarse_space.shape()[1]); - std::copy_n(m_coarse_space.data(), m_coarse_space.shape()[0] * m_coarse_space.shape()[1], coarse_space_mat.data()); // HPDDM deletes the coarse space, so we have to copy. - - return coarse_space_mat; - } - - virtual void compute_coarse_space(py::array_t Ai, py::array_t Bi) = 0; - - void set_coarse_space(py::array_t coarse_space) { - m_coarse_space = coarse_space; - } -}; - -template -class PyGeneoCoarseSpaceDenseBuilder : public GeneoCoarseSpaceBuilderPython { - - public: - /* Inherit the constructors */ - using GeneoCoarseSpaceBuilderPython::GeneoCoarseSpaceBuilderPython; - - // explicit PyGeneoCoarseSpaceDenseBuilder(int size_wo_overlap, Matrix Ai, Matrix Bi, char symmetry, char uplo, int geneo_nu, htool::underlying_type geneo_threshold) : GeneoCoarseSpaceBuilderPython(size_wo_overlap, Ai, Bi, symmetry, uplo, geneo_nu, geneo_threshold) {} - - /* Trampoline (need one for each virtual function) */ - void compute_coarse_space(py::array_t Ai, py::array_t Bi) override { - PYBIND11_OVERRIDE_PURE( - void, /* Return type */ - GeneoCoarseSpaceBuilderPython, /* Parent class */ - compute_coarse_space, /* Name of function in C++ (must match Python name) */ - Ai, - Bi /* Argument(s) */ - ); - } -}; - -template -void declare_geneo_coarse_space_builder(py::module &m, const std::string &className) { - - using Class = GeneoCoarseSpaceBuilder; - py::class_> py_class(m, className.c_str()); - py_class.def(py::init([](int size_wo_overlap, py::array_t Ai, py::array_t Bi, char symmetry, char uplo, int geneo_nu) { - Matrix Ai_mat; - Ai_mat.assign(Ai.shape()[0], Ai.shape()[1], Ai.mutable_data(), false); - Matrix Bi_mat; - Bi_mat.assign(Bi.shape()[0], Bi.shape()[1], Bi.mutable_data(), false); - return Class::GeneoWithNu(size_wo_overlap, Ai_mat, Bi_mat, symmetry, uplo, geneo_nu); - }), - py::arg("size_wo_overlap"), - py::arg("Ai"), - py::arg("Bi"), - py::arg("symmetry"), - py::arg("uplo"), - py::kw_only(), - py::arg("geneo_nu")); - py_class.def(py::init([](int size_wo_overlap, py::array_t Ai, py::array_t Bi, char symmetry, char uplo, double geneo_threshold) { - Matrix Ai_mat; - Ai_mat.assign(Ai.shape()[0], Ai.shape()[1], Ai.mutable_data(), false); - Matrix Bi_mat; - Bi_mat.assign(Bi.shape()[0], Bi.shape()[1], Bi.mutable_data(), false); - return Class::GeneoWithThreshold(size_wo_overlap, Ai_mat, Bi_mat, symmetry, uplo, geneo_threshold); - }), - py::arg("size_wo_overlap"), - py::arg("Ai"), - py::arg("Bi"), - py::arg("symmetry"), - py::arg("uplo"), - py::kw_only(), - py::arg("geneo_threshold")); -} - -template -void declare_virtual_geneo_coarse_space_dense_builder(py::module &m, const std::string &className) { - - using Class = GeneoCoarseSpaceBuilderPython; - py::class_, VirtualCoarseSpaceBuilder> py_class(m, className.c_str()); - py_class.def(py::init([](int size_wo_overlap, py::array_t Ai, py::array_t Bi, char symmetry, char uplo, int geneo_nu) { - Matrix Ai_mat; - Ai_mat.assign(Ai.shape()[0], Ai.shape()[1], Ai.mutable_data(), false); - Matrix Bi_mat; - Bi_mat.assign(Bi.shape()[0], Bi.shape()[1], Bi.mutable_data(), false); - return PyGeneoCoarseSpaceDenseBuilder(size_wo_overlap, Ai_mat, Bi_mat, symmetry, uplo, geneo_nu, -1); - }), - py::arg("size_wo_overlap"), - py::arg("Ai"), - py::arg("Bi"), - py::arg("symmetry"), - py::arg("uplo"), - py::kw_only(), - py::arg("geneo_nu")); - py_class.def(py::init([](int size_wo_overlap, py::array_t Ai, py::array_t Bi, char symmetry, char uplo, double geneo_threshold) { - Matrix Ai_mat; - Ai_mat.assign(Ai.shape()[0], Ai.shape()[1], Ai.mutable_data(), false); - Matrix Bi_mat; - Bi_mat.assign(Bi.shape()[0], Bi.shape()[1], Bi.mutable_data(), false); - return PyGeneoCoarseSpaceDenseBuilder(size_wo_overlap, Ai_mat, Bi_mat, symmetry, uplo, 0, geneo_threshold); - }), - py::arg("size_wo_overlap"), - py::arg("Ai"), - py::arg("Bi"), - py::arg("symmetry"), - py::arg("uplo"), - py::kw_only(), - py::arg("geneo_threshold")); - py_class.def("set_coarse_space", &Class::set_coarse_space); - py_class.def_property_readonly("symmetry", &Class::get_symmetry); - py_class.def_property_readonly("geneo_nu", &Class::get_geneo_nu); - py_class.def_property_readonly("geneo_threshold", &Class::get_geneo_threshold); -} -#endif diff --git a/src/htool/solver/geneo/coarse_space_dense_builder.hpp b/src/htool/solver/geneo/coarse_space_dense_builder.hpp index ad2f00f..d4d70cd 100644 --- a/src/htool/solver/geneo/coarse_space_dense_builder.hpp +++ b/src/htool/solver/geneo/coarse_space_dense_builder.hpp @@ -67,27 +67,27 @@ void declare_geneo_coarse_space_dense_builder(py::module &m, const std::string & Bi_mat.assign(Bi.shape()[0], Bi.shape()[1], Bi.mutable_data(), false); return Class::GeneoWithNu(size_wo_overlap, size_with_overlap, Ai, Bi_mat, symmetry, uplo, geneo_nu); }), - py::arg("size_wo_overlap"), + py::arg("size_wo_overlap"), // LCOV_EXCL_START py::arg("size_with_overlap"), py::arg("Ai"), py::arg("Bi"), py::arg("symmetry"), py::arg("uplo"), py::kw_only(), - py::arg("geneo_nu")); + py::arg("geneo_nu")); // LCOV_EXCL_STOP py_class.def(py::init([](int size_wo_overlap, int size_with_overlap, const HMatrix> &Ai, py::array_t Bi, char symmetry, char uplo, double geneo_threshold) { Matrix Bi_mat; Bi_mat.assign(Bi.shape()[0], Bi.shape()[1], Bi.mutable_data(), false); return Class::GeneoWithThreshold(size_wo_overlap, size_with_overlap, Ai, Bi_mat, symmetry, uplo, geneo_threshold); }), - py::arg("size_wo_overlap"), + py::arg("size_wo_overlap"), // LCOV_EXCL_START py::arg("size_with_overlap"), py::arg("Ai"), py::arg("Bi"), py::arg("symmetry"), py::arg("uplo"), py::kw_only(), - py::arg("geneo_threshold")); + py::arg("geneo_threshold")); // LCOV_EXCL_STOP } template @@ -102,14 +102,14 @@ void declare_virtual_geneo_coarse_space_dense_builder(py::module &m, const std:: Bi_mat.assign(Bi.shape()[0], Bi.shape()[1], Bi.mutable_data(), false); return PyGeneoCoarseSpaceDenseBuilder(size_wo_overlap, size_with_overlap, Ai_mat, Bi_mat, symmetry, uplo, geneo_nu, -1); }), - py::arg("size_wo_overlap"), + py::arg("size_wo_overlap"), // LCOV_EXCL_START py::arg("size_with_overlap"), py::arg("Ai"), py::arg("Bi"), py::arg("symmetry"), py::arg("uplo"), py::kw_only(), - py::arg("geneo_nu")); + py::arg("geneo_nu")); // LCOV_EXCL_STOP py_class.def(py::init([](int size_wo_overlap, int size_with_overlap, py::array_t Ai, py::array_t Bi, char symmetry, char uplo, double geneo_threshold) { Matrix Ai_mat; Ai_mat.assign(Ai.shape()[0], Ai.shape()[1], Ai.mutable_data(), false); @@ -117,14 +117,14 @@ void declare_virtual_geneo_coarse_space_dense_builder(py::module &m, const std:: Bi_mat.assign(Bi.shape()[0], Bi.shape()[1], Bi.mutable_data(), false); return PyGeneoCoarseSpaceDenseBuilder(size_wo_overlap, size_with_overlap, Ai_mat, Bi_mat, symmetry, uplo, 0, geneo_threshold); }), - py::arg("size_wo_overlap"), + py::arg("size_wo_overlap"), // LCOV_EXCL_START py::arg("size_with_overlap"), py::arg("Ai"), py::arg("Bi"), py::arg("symmetry"), py::arg("uplo"), py::kw_only(), - py::arg("geneo_threshold")); + py::arg("geneo_threshold")); // LCOV_EXCL_STOP py_class.def("set_coarse_space", &Class::set_coarse_space); py_class.def_property_readonly("symmetry", &Class::get_symmetry); py_class.def_property_readonly("geneo_nu", &Class::get_geneo_nu); diff --git a/src/htool/solver/solver.hpp b/src/htool/solver/solver.hpp index 2b888fa..8fc9a7f 100644 --- a/src/htool/solver/solver.hpp +++ b/src/htool/solver/solver.hpp @@ -47,12 +47,6 @@ void declare_DDM(py::module &m, const std::string &className) { throw std::invalid_argument("Wrong dimension for right-hand side or solution\nright-hand side: " + rhs + "\n" + "solution: " + sol + "\n"); // LCOV_EXCL_STOP } - // if (b.shape()[0] != self.get_nb_cols()) { - // throw std::invalid_argument("Wrong size for right-hand side"); // LCOV_EXCL_LINE - // } - // if (x.shape()[0] != self.get_nb_rows()) { - // throw std::invalid_argument("Wrong size for solution"); // LCOV_EXCL_LINE - // } self.solve(b.data(), x.mutable_data(), mu); },