ezp
lightweight C++ wrapper for selected distributed solvers for linear systems
abstract_solver.hpp
1 /*******************************************************************************
2  * Copyright (C) 2025-2026 Theodore Chang
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  ******************************************************************************/
17 
18 #ifndef ABSTRACT_SOLVER_HPP
19 #define ABSTRACT_SOLVER_HPP
20 
21 #include "traits.hpp"
22 
23 namespace ezp::detail {
24  template<data_t DT, index_t IT, wrapper_t WT> class abstract_solver {
25  using wrapper_type = WT;
26 
27  protected:
28  static constexpr IT ZERO{0}, ONE{1};
29 
30  template<full_container_t CT> auto to_full(CT&& custom) {
31  if constexpr(has_mem<CT>) return full_mat<DT, IT>{custom.n_rows, custom.n_cols, custom.mem()};
32  else if constexpr(has_memptr<CT>) return full_mat<DT, IT>{custom.n_rows, custom.n_cols, custom.memptr()};
33  else if constexpr(has_data_method<CT>) return full_mat<DT, IT>{custom.n_rows, custom.n_cols, custom.data()};
34  else if constexpr(has_iterator<CT>) return full_mat<DT, IT>{custom.n_rows, custom.n_cols, &(*custom.begin())};
35  else static_assert(always_false_v<CT>, "invalid container type");
36  }
37 
38  public:
39  abstract_solver() = default;
40 
41  virtual ~abstract_solver() = default;
42 
43  template<full_container_t CT> IT solve(CT&& B) { return solve(to_full(B)); }
44 
45  virtual IT solve(WT&&, full_mat<DT, IT>&&) = 0;
46 
47  virtual IT solve(full_mat<DT, IT>&&) = 0;
48  };
49 } // namespace ezp::detail
50 
51 #endif // ABSTRACT_SOLVER_HPP
Definition: abstract_solver.hpp:24
Definition: traits.hpp:85